Nginx+tomcat Alternative Load Balancing

Source: Internet
Author: User

First, the deployment background

A server a:10.68.4.198 domain name: edi.qnb.com (toMCAT application, Web Access but requires account authentication, other server connection query but no authentication ) due to business needs, a server needs to be load balanced. Nginx upstream module is required. Tomcat and Nginx,nginx are installed on the server, forwarding the requests received on port 80 to the 8080 port on this machine, which is handled by Tomcat. The existing server b:10.68.4.248 with the same configuration is used to load balance a.

Follow the general settings to add the following two sentences directly to the upstream block, but this is the case. Web Access is going to be a problem and thesession is missing . Will always be the landing screen. However, Nginx perfectly solves this problem. That's using Ip_hash.

Ip_hash: The ability to locate a client's IP request through a hashing algorithm to the same back-end server.

Upstream edi.qnb.com {ip_hash;                Server 127.0.0.1:8080;        Server 10.68.4.248:8080; }

The ip_hash can really solve the problem of session loss. But the same IP will always only be reversed to a server, Web Access can be load-balanced, then the server access it? Server A is mostly accessed by other server connections. So Ip_hash can only resolve Web Access, not the server.

My idea: After discussing with colleagues, I decided to configure two domain names on nginx. One for Web access and no load handling (relatively few accesses). The other is used as a server-to access, doing load processing. This solves both the Web Access session problem. It is also reasonable to load the server connection request. Next, I will post my configuration file for your reference.      


Second, configuration changes

First modify the Nginx configuration file nginx.conf

  #1, qnb.edi.com this domain for user Web Access.         upstream qnb.edi.com {                 server 127.0.0.1:8080;         }        server {                 listen  80;                 server_name   qnb.edi.com;                 proxy_redirect off;                 location / {                         proxy_store off;                         access_log /data/log/nginx/access.log main;                          proxy_pass http://qnb.edi.com;                 }        } #2, edi.qnb.com This domain name is used for server access. Authentication is not required between servers.         upstream edi.qnb {                 server 127.0.0.1:8080;                 server  10.68.4.248:8080;        }         server {                listen  80;                 server_name   edi.qnb.com;                 proxy_redirect off;                 location / {                         proxy_store off;                          access_log /data/log/nginx/access.log main;                          proxy_pass http://edi.qnb;                 }        }

         Next, modify the configuration file for Tomcat on 4.198 and 4.248 server.xml

   Tomcat configuration file on #1, 4.198      


Third, testing

First affirm that edi.qnb.com and qnb.edi.com. These two domain names are I casually obtain, actually does not exist. Therefore, when using domain name access, please add the following information on the local hosts file. Path to the Hosts file on Windows : C:\Windows\System32\drivers\etc

10.68.4.198 qnb.edi.com10.68.4.198 edi.qnb.com

Test access edi.qnb.com to see if the payload is available.

This is my solution. May be different from many great gods online. Younger brother is still studying in ~ ~ ~, do not like to spray!


Iv. my questions?

When I configured nginx.conf and Server.xml, there was one piece that I didn't figure out. Search the Internet for a lot of information, but did not find a detailed explanation of the relationship between the article. The great God who has been posted here and knows the answers to my doubts.

The virtual host in the nginx.conf.

server_name edi.qnb.com;

Virtual hosts in the Server.xml

Why do the names of the two virtual hosts have to be the same? Can a great God give me an explanation ...

Unofficial explanation: I was so understanding, a full Web server, a front-end browser access to--nginx, back-end processing request data--tomcat. After these two are together, a complete Web server is formed. So the host name must be the same!!!

2015.8.28 11:46 Forgive me for my bohemian culture, and I've just seen articles about "Tomcat for multi-domain configuration." The above problems can be ignored.


Nginx+tomcat Alternative Load Balancing

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.