After multiple tomcat servers are used for load balancing, the tomcat port is not open to the public, so the tomcat server Load balancer can be accessed precisely.
Use Nginx and two Tomcat servers to achieve load balancing, disable tomcat ports (8080 and 8090) in the firewall, and open only port 80 to the outside. Nginx configuration: upstream tomcatCluster {server <ip>: 8080; server <ip>: 8090 ;}
Server {listen 80; server_name dev.xjj.cn ...... Location /{...... Location ~ */<Project-name>/servlet/{include proxy. conf; proxy_pass http: // tomcatCluster ;}}......}
Note:The two tomcat ports are 8080 and 8090 respectively. The location statement distributes requests evenly to the two tomcat Servers Based on the keyword "/<project-name>/servlet/" in the request URI.
After a tomcat upgrade, You need to directly access its page to test whether there is any error.
The Tomcat port has been disabled by the firewall for external access and cannot be directly accessed through "http: // <ip>: 8080/" or "http: // <ip>: 8090/"access a tomcat for testing. The solution can only be forwarded through Nginx.
You can use Nginx rewrite and proxy_pass to directly access a tomcat. The configuration and explanation are as follows. Add two location configurations in Nginx location configuration: # port 8080 test page dedicated location ~ */Tomcat8080-<project-name>/{include proxy. conf; rewrite ^/tomcat8080-(. *)/$1 break; proxy_pass http: // 192.168.0.9: 8080 ;}
# Port 8090 test page dedicated location ~ */Tomcat8090-<project-name>/{include proxy. conf; rewrite ^/tomcat8090-(. *)/$1 break; proxy_pass http: // 192.168.0.9: 8090 ;}
Note (take the second example ):Rewrite statement: Replace the request URI http://dev.xjj.cn/tomcat8090-<project-name>/*** with the http://dev.xjj.cn/<project-name>/*** proxy_pass statement: replace the request http://dev.xjj.cn/<project-name>/*** with http: // 192.168.0.9: 8090/<project-name> /***
In this way, the combination of rewrite and proxy_pass statements enables precise access to a tomcat.