[Switch] Nginx + Tomcat load balancing

1. What is Nginx?

        nginx [engine x] is an HTTP and reverse proxy server written by Igor Sysoev, and it can also act as a mail proxy server. It has been used for a long time on many high-traffic Russian sites, including Yandex, Mail.Ru, VKontakte, and Rambler. According to Netcraft statistics, in August 2012, 11.48% of the world's busiest websites use Nginx as their server or proxy server (see: http://nginx.org/cn/ or google).

 

2. Nginx+Tomcat configuration under Windows

        Nginx :http://nginx.org/

        Tomcat:http://tomcat.apache.org/

    My local environment is Windows XP+Nginx 1.0.15+ apache-tomcat-7.0.34

        1. Nginx installation: Nginx download and decompress to any directory without spaces and Chinese characters on the machine.

            

        2, conf/nginx.conf configuration file modification

            a: Modify Nginx default port:

                

Conf code    Favorite code
  1. server {  
  2.         listen       80;  
  3.         server_name  localhost;  
  4.         ......  
  5. }  

              The listen here is listening, the default port is 80, if necessary, it can be changed to other ports.

            b: increase after keepalive_timeout

 

Conf code    Favorite code
  1. upstream location {  
  2.     The #weigth parameter represents the weight, the higher the weight, the greater the probability of being assigned  
  3.     server 127.0.0.1:8048 weight=3;  
  4.     server 127.0.0.1:8049 weight=2;  
  5.     ip_hash;  
  6. }  

 

 

            c: modify

 

Conf code    Favorite code
  1. location / {  
  2.         root    html;  
  3.     index   index.html index.htm;  
  4. }  

 

 

               for

             

Conf code    Favorite code
  1. location / {  
  2.             root    html;  
  3.         index   index.html index.htm;  
  4.         proxy_pass  http://location;  
  5.         proxy_redirect  off;  
  6.         proxy_set_header    Host $host;  
  7.         proxy_set_header    X-Real-IP $remote_addr;  
  8.         proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;  
  9.         client_max_body_size    10m;  
  10.         client_body_buffer_size 128k;  
  11.         proxy_connect_timeout   90;  
  12.         proxy_send_timeout  90;  
  13.         proxy_read_timeout  90;  
  14.         proxy_buffer_size   4k;  
  15.         proxy_buffers   4 32k;  
  16.         proxy_busy_buffers_size 64k;  
  17.         proxy_temp_file_write_size  64k;  
  18. }  

 

 

         3. Modify the port configuration in Tomcat server.xml so that this machine can run multiple Tomcats. Note that the Tomcat publishing port should be the same as the mapped port in 2.a.

 

At this point, the configuration is complete, enter http://127.0.0.1:80 (or custom port) to access

 

Reprinted from: http://guomingjun.iteye.com/blog/1939158

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326618118&siteId=291194637