nginx配置负载均衡

来源:互联网 发布:半径算法 编辑:程序博客网 时间:2024/06/04 00:26

1.打开nginx配置文件

cd /usr/local/nginx/conf/nginx.conf

2.在http结点添加配置

/*在http这个节下面配置一个叫upstream的,后面的名字可以随意取,但是要和location下的proxy_pass http://后的保持一致。*/http {    #是在http里面的, 已有http, 不是在server里,在server外面    upstream tomcats {         #weight表示权重        server 192.168.0.88:8080 weight=1;        server 192.168.0.89:8080 weight=1;        server 192.168.0.90:8080 weight=1;    }    #卸载server里    location ~ .*\.(jsp|do|action) {        #tomcats是后面的tomcat服务器组的逻辑组号        proxy_pass http://tomcats;            }}

3.检查配置文件是否正确

./nginx -t

4.重启nginx

./nginx -s reload