server1:192.168.200.113(nginx服务端)
server2:192.168.200.111(Tomcat服务端)
server1中nginx的配置文件 nginx.conf
http{ 略 upstream tomcat_server { server 192.168.200.111:8080 weight=1; //指定Tomcat地址,weight值越高,负载越大 #server 192.168.200.112:8080 weight=1;
#server 192.168.200.113:8080 weight=1;
} server { 略 location / { root html; index index.html index.htm; proxy_pass http://tomcat_server; //要与前面设置的名称相同
proxy_set_header Host $http_host; //重写请求头中的host字段,否则会报400错误 } } }