Nginx as a Load Balancer server (Windows environment)

Source: Internet
Author: User

One of the simplest load-balancing tests, which does not involve session replication, simply assigns the request to a different server.

1. Create a simple Web application. There is only one index.jsp page, the content is as follows.

<%@ page language= "java"  pageencoding= "UTF-8"%><! DOCTYPE html>            hello,nginx!            <%                System.out.println ("*****************nginx do load Balancing to assign requests to this server *****************");              %>  </body>

Print a word on the OK, can be printed on different servers, indicating that the request was assigned to a different server.

2, Configuration nginx.conf

1) Add the following to the HTTP node

    Upstream localhost {server        localhost:18080;//tomcat server-1th server        LOCALHOST:28080;//TOMCAT Servers-# 2nd    }

2) Add the following content to the server node content in the HTTP node

Location/{        proxy_pass http://localhost;}

3. Deploy the Web application to two Tomcat servers, launch two Tomcat, and start Nginx. Then visit http://localhost/index.jsp to see what the two Tomcat servers are printing

4, the above is the default use of polling to achieve load balancing, there are two other ways

Least connected (assigning requests to the most idle server)

Upstream localhost {        least_conn;        Server localhost:18080;        Server localhost:28080;}        

Ip_hash (the request is assigned to some fixed server based on the client IP)

Upstream localhost {        ip_hash;        Server localhost:18080;        Server localhost:28080;}

5, in the way of polling, you can also specify the server to accept the weight of the request

  

Upstream localhost {        server localhost:18080 weight=2;        Server localhost:28080 weight=1;    }

Nginx as a Load Balancer server (Windows environment)

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.