Nginx + Tomcat Configuration Load Balancer

Source: Internet
Author: User

Target: Nginx as Httpserver, connect multiple Tomcat application instances, load balance.

Note: This example takes a machine as an example, that is, the same machine is loaded with an nginx and 2 tomcat and installed JDK1.7.

1. Installing Nginx
Installing Nginx Tutorials

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

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

<! DOCTYPE HTML > <  lang= "en">    <head>This is 8081 Port</head></html>

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

<! DOCTYPE HTML > <  lang= "en">    <head>This is 8082 Port</head></html>

Configure multiple Tomcat tutorials on the same server

So we successfully built a Nginx service, successfully configured two Tomcat application instances.

3. Nginx+tomcat Load Balancing Configuration
Only the Nginx configuration needs to be modified so that it can be forwarded via Tomcat.
A, nginx.conf configuration file

Worker_processes  1; events {    worker_connections  ;} HTTP {    include       mime.types;    Default_type  application/octet-stream;    Sendfile on        ;    Keepalive_timeout  ;    Include extra/upstream01.conf;}

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

upstream MySite {    server localhost:8081 weight=5;    Server localhost:8082 weight=5;} server {    ;    server_name localhost;       / {    proxy_pass http://MySite;     }}

When a request is sent to localhost, the request is distributed to the list of servers for the corresponding upstream settings, and every server requested for distribution is random.

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

This indicates that the load Balancer configuration was successful!!!!!!

Nginx + Tomcat Configuration Load Balancer

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.