Nginx负载均衡配置

2017.10.15 nginx

1.服务器环境

192.168.100.168做集群服务器,安装nginx,nginx使用80端口 192.168.100.169-171做应用服务器,安装nginx,nginx使用80端口 169-171的分别启动tomcat,tomcat端口为8080

2.集群服务器nginx.conf配置

http {
    ...
    access_log off;
    client_max_body_size 1024m;
    upstream www.servers.com {
        ip_hash;
	server 192.168.100.169:80;
	server 192.168.100.170:80;
	server 192.168.100.171:80;
    }
    ...
    server {
        listen       80;
	server_name  servers;
	...
	location / {
	    #root   html;
	    #index  index.html index.htm;
	    proxy_pass http://www.servers.com;
	    proxy_set_header Host $host;
	    proxy_set_header X-Real-IP $remote_addr;
	    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	}
	...
    }
}

3.应用服务器nginx.conf配置

http {
    ...
    access_log off;
    client_max_body_size 1024m;
    ...
    server {
        listen       80;
	server_name  servers;
	...
	location / {
	    #root   html;
	    #index  index.html index.htm;
	    proxy_pass http://192.168.100.169:8080;
	}
	...
    }
}

170和171服务器同上配置修改ip即可

更新列表:

参考文章:

相关阅读