Nginx+tomcat to realize load balancing _nginx

Source: Internet
Author: User

Implementation of load Balancing configuration
1. Reverse Proxy

2, implementation agent (192.168.1.161 Agent to 192.168.1.62)

Worker_processes 1;
events{
    worker_connections 1024;
}
http{
    include mine.types;
    Default_type Application/octet-stream;
    Senfile on;
    Keepalive_timeout;

    server{
        Listen;
        server_name locahost;
        Location/{
            #root html;
            Index index.html index.htm;
            Proxy_pass http://192.168.1.62:8080; # Agent to http://192.168.1.62:8080
        }

        error_page 502 503 504/50x.html;
        Location =/50x.html {
            root html;
        }

}} Restart Nginx:./nginx-s Reload


Second, the processing strategy of session during load balancing
1. Achieve Basic load Balancing

# Set up the server group, the policy is the default policy, the average polling (1) upstream Tomcats {server 192.168.1.62:8080;
Server 192.168.1.63:8080;
    # Set up the server group, the policy is Ip_hash policy, the user is locked to a server (2) upstream Tomcats {ip_hash;
    Server 192.168.1.62:8080;
Server 192.168.1.63:8080;
    # Configure server group information for load Balancing (5) Upstream backends{server 192.168.1.62:8080 backup;

    Server 192.168.1.63;

    # Weight: Weight, the higher the value the larger the load (by weight decision polling) # server 192.168.1.4 weight=5;

    # Backup: back-up machine, only if not the backup machine is dead to enable; server 192.168.1.4 backup; 

    # Down: Stop sign, will not be accessed, mainly for temporary downtime maintenance server 192.168.1.65 down;
# Max_fails: To the specified number of times that the server hangs up # Fail_timeout: How long before you hang up to test if the server 192.168.1.66 max_fails=2 fail_timeout=60s has been restored;
} worker_processes 1;
    events{worker_connections 1024; http{include mine.types;
    Default_type Application/octet-stream;
    Senfile on;

    Keepalive_timeout 65;
        server{Listen 80;
        server_name locahost;
            Location/{#root html;
            Index index.html index.htm; ProXy_pass Http://tomcats;
        # Send current access to server group} Error_page 502 503 504/50x.html;
        Location =/50x.html {root html; }
    }
}


Each time you refresh, the server being proxied is different, the default average polling. The balance strategy includes
(1) None polling, weight determined by weight
(2) Ip_hash, a user bound to a server
(3) Fair strategy, according to the speed of the server response dynamic allocation, response fast load
(4) Url_hash,url binding on a server

Three, the problem that the application code should pay attention to in the cluster environment

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.