Nginx Tomcat for load balancing

Source: Internet
Author: User
Tomcat using Nginx for load balancing is a simple thing

1. Environment preparation

The two machine IPs are 192.168.0.166 192.168.0.167 , respectively.

of which 166 installed Nginx

166 and 167 to install Tomcat separately

Of course, you can choose another machine to install nginx because I don't have that machine, so I installed Nginx in 166.

2. Configuration files

The basic configuration of Nginx is described in the previous article, which only needs to be configured with the following two sections on the basic configuration.

 
 
  1. #使用域名 www.test.com(可以自己随便定义,也可以使用IP地址)
  2. upstream www.test.com {
  3. #server is the two tomcat ports that you want to achieve load balancing by default, 8080,IP is 166 and 167.
  4. server 192.168.0.166:8080;
  5. server 192.168.0.167:8080;
  6. }
  7. Server {
  8. listen 80;
  9. server_name www.test.com;
  10. #charset koi8-r;
  11. #其中~^/rzdb 是一个正则表达式,意思是只要访问的地址中出现rzdb(也就是我的项目名字)
  12. location ~^/rzdb {
  13. proxy_pass http://www.test.com;
  14. proxy_set_header Host $host;
  15. proxy_set_header X-Real-IP $remote_addr;
  16. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  17. }

Configuration complete, start Nginx.

Access to http://www.test.com/rzdb/index.html access successfully;


The above describes the Nginx tomcat to achieve load balancing, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

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