From 21a25da015d2ee46b09d72bb342abce6fd55b0f2 Mon Sep 17 00:00:00 2001 From: s_jqzhang Date: Thu, 30 May 2019 14:39:03 +0800 Subject: [PATCH] add nginx cluster config --- fileserver.go | 11 +++++---- nginx/README.md | 8 +++++++ nginx/gofastdfs-cluster.conf | 45 ++++++++++++++++++++++++++++++++++++ nginx/gofastdfs.conf | 11 +++++---- 4 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 nginx/README.md create mode 100644 nginx/gofastdfs-cluster.conf diff --git a/fileserver.go b/fileserver.go index ec1a1987..764d47c9 100644 --- a/fileserver.go +++ b/fileserver.go @@ -3181,6 +3181,11 @@ func (this *Server) Index(w http.ResponseWriter, r *http.Request) { } } func init() { + flag.Parse() + if *v { + fmt.Printf("%s\n%s\n%s\n%s\n", VERSION, BUILD_TIME, GO_VERSION, GIT_VERSION) + os.Exit(0) + } DOCKER_DIR = os.Getenv("GO_FASTDFS_DIR") if DOCKER_DIR != "" { if !strings.HasSuffix(DOCKER_DIR, "/") { @@ -3206,7 +3211,7 @@ func init() { os.MkdirAll(folder, 0775) } server = NewServer() - flag.Parse() + peerId := fmt.Sprintf("%d", server.util.RandInt(0, 9)) if !server.util.FileExists(CONST_CONF_FILE_NAME) { peer := "http://" + server.util.GetPulicIP() + ":8080" @@ -3617,10 +3622,6 @@ func (HttpHandler) ServeHTTP(res http.ResponseWriter, req *http.Request) { http.DefaultServeMux.ServeHTTP(res, req) } func (this *Server) Main() { - if *v { - fmt.Printf("%s\n%s\n%s\n%s\n", VERSION, BUILD_TIME, GO_VERSION, GIT_VERSION) - return - } go func() { for { this.CheckFileAndSendToPeer(this.util.GetToDay(), CONST_Md5_ERROR_FILE_NAME, false) diff --git a/nginx/README.md b/nginx/README.md new file mode 100644 index 00000000..bd0279c4 --- /dev/null +++ b/nginx/README.md @@ -0,0 +1,8 @@ +## 注意点: +``` + 一、如果不知道文件大小时,需设置 + client_max_body_size 0; + 二、如果要开启tus,并使用nginx反向代理,需要设置proxy_redirect + 并且重定向 + proxy_redirect ~/(\w+)/big/upload/(.*) /$1/big/upload/$2; #继点续传一定要设置(注意) +``` diff --git a/nginx/gofastdfs-cluster.conf b/nginx/gofastdfs-cluster.conf new file mode 100644 index 00000000..6f7649b3 --- /dev/null +++ b/nginx/gofastdfs-cluster.conf @@ -0,0 +1,45 @@ +worker_processes 1; +events { + worker_connections 1024; +} +http { + include mime.types; + default_type application/html; + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + access_log /var/log/nginx/access.log main; + error_log /var/log/nginx/error.log error; + sendfile on; + keepalive_timeout 65; + #rewrite_log on; + client_max_body_size 0; + proxy_redirect ~/(\w+)/big/upload/(.*) /$1/big/upload/$2; #继点续传一定要设置(注意) + upstream gofastdfs-group1 { + server 10.1.51.70:8082; + server 10.1.14.37:8080; + ip_hash; #notice:very important(注意) + } + upstream gofastdfs-group2 { + server 10.1.51.70:8083; + server 10.1.14.36:8083; + ip_hash; #notice:very important(注意) + } + server { + listen 8000; + server_name localhost; + location /group1 { #以下header要设置 + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_pass http://gofastdfs-group1; + } + location /group2 {#以下header要设置 + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_pass http://gofastdfs-group2; + } + + } +} \ No newline at end of file diff --git a/nginx/gofastdfs.conf b/nginx/gofastdfs.conf index 33d462af..7a653553 100644 --- a/nginx/gofastdfs.conf +++ b/nginx/gofastdfs.conf @@ -12,17 +12,20 @@ http { error_log /var/log/nginx/error.log error; sendfile on; keepalive_timeout 65; + client_max_body_size 0; + proxy_redirect ~/big/upload/(.*) /big/upload/$1; #继点续传一定要设置(注意) upstream go-fastdfs { server 10.1.14.36:8080; - ip_hash; #notice:very important + server 10.1.14.37:8080; + ip_hash; #notice:very important(注意) } server { listen 80; server_name localhost; location / { - proxy_set_header Host $host; #notice:very important - proxy_set_header X-Real-IP $remote_addr; #notice:very important - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #notice:very important + proxy_set_header Host $host; #notice:very important(注意) + proxy_set_header X-Real-IP $remote_addr; #notice:very important(注意) + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #notice:very important(注意) proxy_pass http://go-fastdfs; }