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.

Source: Internet
Author: User

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.

  • Background:
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.
  • Requirements:
After a tomcat upgrade, You need to directly access its page to test whether there is any error.
  • Requirement Analysis:
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.
  • Solution:
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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.