Nginxtomcat implements load balancing

Source: Internet
Author: User
: This article mainly introduces nginxtomcat to achieve load balancing. if you are interested in the PHP Tutorial, please refer to it. Using nginx in tomcat to achieve load balancing is very simple.

1. prepare the environment

The IP addresses of the two machines are 192.168.0.166 192.168.0.167.

Nginx 166 installation

Install tomcat in 166 and 167 respectively

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

2. configuration file

In the previous article, we talked about the basic configuration of nginx. here we only need to add the following two configurations to the basic configuration.

 
  1. # Use the domain name www.test.com (you can define it yourself or use an IP address)
  2. upstream www.test.com {
  3. # Server is the default port number of the two tomcat servers for load balancing. the default ip addresses are 8080 and 166.
  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. # Where ~ ^/Rzdb is a regular expression, meaning that rzdb (my project name) appears in the Accessed address)
  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. }

After the configuration is complete, start nginx.

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


The above section describes how to implement load balancing for nginx tomcat, including some content. I hope to help anyone who is interested in PHP tutorials.

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.