Nginx负载均衡配置

    #负载均衡配置
	upstream cx_load{
		server localhost:8081 weight=1;
		server 10.5.2.35:8082 weight=2;
	}
	
    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass http://cx_load;
			proxy_pass_header Date;
		    proxy_pass_header Server;
		    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_http_version 1.1;
		    proxy_set_header Upgrade $http_upgrade;
		    proxy_set_header Connection "upgrade";
        }
    }

需要对代理进行配置,否则会出现400 bad Request错误。

            proxy_pass_header Date;
            proxy_pass_header Server;
            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_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";

你可能感兴趣的:(架构师之路,nginx,负载均衡)