When multiple tomcat servers are used for load balancing and the tomcat port is not open to the outside world, the method for precise tomcat access is implemented.

Source: Internet
Author: User
: 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.
  • 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. 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.

  • 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 :// : 8080/"or" http :// : 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:

#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.

Related Article

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.