When a single application is already unable to cope with the increasing volume of traffic, we tend to use distributed deployment, where the next single-Nginx combined with multiple tomcat for single-application deployment:
1, using upstream, in the Nginx nginx.conf file add the following configuration: http {# ..... Other configurations are omitted here upstream abc.test.com {server 192.168.0.1:8081 weight=1 max_fails=2 fail_timeout=30s; Server 192.168.0.1:8082 weight=1 max_fails=2 fail_timeout=30s;server 192.168.0.2:8081 weight=1 max_fails= 2 fail_timeout=30s;server 192.168.0.2:8082 weight=1 max_fails=2 fail_timeout=30s;} # ..... This omits other configuration} 2, adds a server, corresponds to the domain of the application that is visited, such as www.test.comserver{ Listen 80; server_name www.test.com; &NB Sp CharSet utf-8; location/{ &NBSP ; Proxy_pass http://abc.test.com; &NBS P }   3, 2 tomcat installed on 192.168.0.1 and 192.168.0.2 two servers, ports 8081,80824, restart Nginx, configuration effective nginx-s RELOAD5, the above configuration, the entire system can operate normally, but our program will often have to obtain the user's real IP needs, But based on the above configuration can only get to the intranet address 192.168.0.1 and 192.168.0.2 to get the real IP address, you need to change the configuration of the second step to: Server{listen 80;server_name Www.test.com;charset Utf-8;location/{Proxy_pass http://abc.test.com; proxy_set_header x-forwarded-for $proxy _add_x_ Forwarded_for;}} Also in Java applications this gets: Request.getheader ("X-forwarded-for"), 6, at this time, if the system calls Request.getservername (), the return is also the intranet IP, Instead of www.test.com, you need to add the following configuration Proxy_set_header Host $host; Note: This can be returned correctly when Nginx and Tomcat are on a single server.
Nginx Balanced Multi-tomcat environment configuration, and REMOTEIP and servername access in this environment