Load balancing was implemented with Nginx and two Tomcat, and Tomcat ports (8080 and 8090) were closed in the firewall, and only 80 ports were opened externally. The Nginx configuration is as follows:
Upstream Tomcatcluster {
Server : 8080;
Server : 8090;
}
Server
{
Listen 80;
server_name dev.xjj.cn
......
Location/{
......
Location ~*/ /servlet/{
Include proxy.conf;
Proxy_pass Http://tomcatCluster;
}
}
......
}
Note: The two tomcat ports are 8080 and the 8090,location statement distributes the request evenly to two Tomcat based on the keyword "//servlet/" in the request URI.
When one of the Tomcat is upgraded, it is necessary to directly access its pages to test for errors.
The tomcat port has been blocked from external access by the firewall and cannot be tested directly by accessing a tomcat with "http:/-8080/" or "http : 8090/". The resolved method can only be forwarded via Nginx.
The direct access to a tomcat can be achieved through Nginx rewrite combined with Proxy_pass, which is configured and interpreted as follows, adding two location configurations to the Nginx location configuration:
#8080端口测试页面专用
Location ~*/tomcat8080- /{
Include proxy.conf;
Rewrite ^/tomcat8080-(. *)/$1 break;
Proxy_pass http://192.168.0.9:8080;
}
#8090端口测试页面专用
Location ~*/tomcat8090- /{
Include proxy.conf;
Rewrite ^/tomcat8090-(. *)/$1 break;
Proxy_pass http://192.168.0.9:8090;
}
Note (Take the second as an example):
Rewrite statement: Replace the request URI http://dev.xjj.cn/tomcat8090- /*** with the http://dev.xjj.cn/ /***
Proxy_pass statement: Replace the request http://dev.xjj.cn/ /*** with the http://192.168.0.9:8090/ /***
This enables precise access to a tomcat through the combination of rewrite and proxy_pass statements.
The above describes the use of multiple tomcat to achieve load balancing, the Tomcat port is not open to the situation, to achieve accurate access to Tomcat, including aspects of the content, I hope that the PHP tutorial interested in a friend to help.