A method for precise access to Tomcat when the Tomcat port is not open when using multiple tomcat for load balancing

Source: Internet
Author: User
Tags php tutorial
    • Background:

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.

    • Demand:

When one of the Tomcat is upgraded, it is necessary to directly access its pages to test for errors.

    • Requirements Analysis:

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.

    • Solution:

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.

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