Skip to content

Commit

Permalink
add nginx cluster config
Browse files Browse the repository at this point in the history
  • Loading branch information
sjqzhang committed May 30, 2019
1 parent e416195 commit 21a25da
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 9 deletions.
11 changes: 6 additions & 5 deletions fileserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "/") {
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions nginx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## 注意点:
```
一、如果不知道文件大小时,需设置
client_max_body_size 0;
二、如果要开启tus,并使用nginx反向代理,需要设置proxy_redirect
并且重定向
proxy_redirect ~/(\w+)/big/upload/(.*) /$1/big/upload/$2; #继点续传一定要设置(注意)
```
45 changes: 45 additions & 0 deletions nginx/gofastdfs-cluster.conf
Original file line number Diff line number Diff line change
@@ -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;
}

}
}
11 changes: 7 additions & 4 deletions nginx/gofastdfs.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 21a25da

Please sign in to comment.