大容量(海量)存储nginx配置(横向扩展) - sjqzhang/go-fastdfs GitHub Wiki

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 ,一个小群集内按业务需求设定副本数,也就是机器数。
        upstream gofastdfs-group1 {
                server 10.1.51.70:8082;
                #server 10.1.14.37:8082;
                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 ~ /godfs/group(\d) { 
                    #统一在url前增加godfs,以便统一出入口。
                    proxy_set_header Host $host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
                    rewrite ^/godfs/group(\d) /group$1 break;
                    proxy_pass http://gofastdfs-group$1;
                }
                location ~ /godfs/upload { 
                    #这是一个横向扩展配置,前期可能只有一个集群group1,当group1满后,只需将上传指向group2,
                    #也就是将rewrite , proxy_pass 中的group1改为group2即可。
                    proxy_set_header Host $host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
                    rewrite ^/godfs/upload /group1/upload break;
                    proxy_pass http://gofastdfs-group1;
                }
                location ~ /godfs/big/upload { 
                    #以上上类似。
                    proxy_set_header Host $host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
                    rewrite ^/godfs/upload /group1/big/upload break;
                    proxy_pass http://gofastdfs-group1;
                }

        }
}