: This article mainly introduces how to precisely access tomcat when the tomcat port is not open to the outside when multiple tomcat servers are used for load balancing, if you are interested in the PHP Tutorial, refer.
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. 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 8090 respectively. the location statement is based on the keyword "/ /Servlet/"distributes requests evenly to two tomcat servers.
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 :// : 8080/"or" http :// : 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:
#8080 port test page dedicated
Location ~ */Tomcat8080- /{
Include proxy. conf;
Rewrite ^/tomcat8080-(. *)/$1 break;
Proxy_pass http: // 192.168.0.9: 8080;
}
#8090 Port test page dedicated
Location ~ */Tomcat8090- /{
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 request http://dev.xjj.cn/<project-name>/*** with http: // 192.168.0.9: 8090/ /***
In this way, the combination of rewrite and proxy_pass statements enables precise access to a tomcat.
The preceding section describes how to precisely access tomcat when the tomcat port is not open to the outside when multiple tomcat servers are used for load balancing, if you are interested in PHP tutorials.