Nginx虚拟主机以及负载均衡配置

来源:互联网 发布:apache ant zip.jar 编辑:程序博客网 时间:2024/06/06 03:01

Nginx虚拟主机以及负载均衡配置

1.nginx安装配置请参考前文:http://blog.csdn.net/java__han/article/details/77483015;

2.个人测试,装了三台tomcat服务器,分别配置不同的端口,跑起来;
端口号分别为:8080 、8081、8082

3.在nginx.conf添加以下代码:
        upstream tomcats{        server 172.20.16.130:8080 weight=2;        server 172.20.16.130:8081;        server 172.20.16.130:8082;        }        server {        listen       80;        server_name  tomcat.hansuo.com;        location / {            proxy_pass   http://tomcats;            index  index.html index.htm;        }   }
4.修改host
因为配置了虚拟域名,所以要修改host
在C:\Windows\System32\drivers\etc打开host,添加
172.20.16.130 tomcat.hansuo.com
5.启动nginx.
成功,简单配置负载均衡。
原创粉丝点击