A method for configuring load Balancing under Windows Nginx+tomcat _nginx

Source: Internet
Author: User
Tags server port

Objective: Nginx as Httpserver, connecting multiple Tomcat application instances for load balancing.

Note: This routine is an example of a machine that has a nginx and 2 tomcat installed on the same machine and JDK1.7.

1. Installation Nginx
Install Nginx Tutorial

2. Configure two Tomcat
Configure two tomcat on this machine, tomcat7-8081, tomcat7-8082, respectively.
tomcat7-8081 Access Address: http://localhost:8081, browse display: This is 8081 port
tomcat7-8082 Access Address: http://localhost:8082, browse display: This is 8082 port

The contents of the D:\div\tomcat7-8081\webapps\ROOT\index.jsp file are:

<! DOCTYPE html>

 
 

The contents of the D:\div\tomcat7-8082\webapps\ROOT\index.jsp file are:

<! DOCTYPE html>

 
 

Configuring multiple Tomcat tutorials on the same server

If you are configuring multiple tomcat on a single server, it is primarily to avoid the problem of port conflicts on Tomcat servers. Just modify the boot port and the connection port in the catalina_home\conf\server.xml to be OK!

Below we write down the detailed process of the configuration below for reference: (This example configures three Tomcat cases) 1. Download apache-tomcat-7.0.63, download the file for Apache-tomcat-7.0.63.zip 2.
Unzip the compressed package into the d:/div/directory. 3. Modify the Unpacked folder name: tomcat7-8080 4. Create two copies of the folder in the d:/div/directory, renamed to: tomcat7-8081, tomcat7-8082 5, respectively. To add an environment variable: Right-click My Computer-> Select Properties-> Select Advanced-> Select environment variable: Add system variable: catalina_home_8080, its value is: D:\div\tomcat7-8080; catalina_home_ 8081, the value is: D:\div\tomcat7-8081 catalina_home_8082, the value is: D:\div\tomcat7-8082 6. Modify boot port and shutdown port: Enter D:\div\tomcat7-8081\conf\ directory, open server.xml file, modify the following two places: (1) <server port= "8006" shutdown= "Shutdown"
> Modify this port= "8006", the original default is: 8005, so that its closed port and another shutdown port does not conflict.
        (2) <connector port= "8081" maxhttpheadersize= "8192" maxthreads= "75" minsparethreads= " Enablelookups= "false" redirectport= "8443" acceptcount= "connectiontimeout=" 20000 "disableuploadtimeout="
"True"/> Modify port= "8081", the original default is "8080", so that its connection port and the other does not conflict. (3) <connector port= "8009" protocol= "ajp/1.3" redirectport= "8443"/> Modify this port= "8010", the original default is: 8009,AJP 1.3

Connector defines the place. 7.Modify the contents of the Startup.bat and Catalina.bat files: (1) Open the D:\div\tomcat7-8081\bin\startup.bat file and replace all catalina_home with Catalina_home_
8081.

(2) Open the D:\div\tomcat7-8081\bin\catalina.bat file and replace all catalina_home with catalina_home_8081.

The tomcat7-8082 configuration method is the same as configuring the tomcat7-8081 step. 8. Start Tomcat, enter three different Tomcat installation directories under the command line, execute Startup.bat, and start three Tomcat respectively. Then enter in the browser: http://localhost:8080 http://localhost:8081 http://localhost:8082 9. At this point, we have configured three tomcat on a single server.

In this way we have successfully built a Nginx service and successfully configured two Tomcat application instances.

3. Nginx+tomcat Load Balance Configuration
Here you only need to modify the Nginx configuration so that it is forwarded via Tomcat.
A, nginx.conf configuration file

Worker_processes 1;

Events {
  worker_connections 1024;
}

HTTP {
  include    mime.types;
  Default_type Application/octet-stream;
  Sendfile on    ;
  Keepalive_timeout;
  Include extra/upstream01.conf;
}

b, extra/upstream01.conf file, load Balancing configuration information

Upstream MySite {
  server localhost:8081 weight=5;
  Server localhost:8082 weight=5;
}
 
server {
  listen;
  server_name localhost;
 
  Location/{
  proxy_pass http://mysite;
  }
}

When there is a request to localhost, the request is distributed to the server list of the corresponding upstream settings, and each server that requests the distribution is random.

Then, when you run the start Nginx, when you constantly refresh the http://localhost, the browser switches back and forth between "This is 8081 port" and "This is 8082 port".

This shows that the load balancing configuration was successful!!!!!!

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.