Nginx 의 역방향 대리 와 부하 균형 실현 동정 분리 실전

3753 단어
                ,               ,                 
         ,                    ,                    ,             ,        ,                        ,           。
Nginx http
ngx_nginx upstream             ,                     

ngx_http_proxy_module      Proxy  ,              upstream    
Nginx upstream 5 。 , Nginx , :
1)rr       
           upstream       ,                        ,      
   down  ,     。  1:1  。
        upstream backend {
            server 192.168.1.101:88;
            server 192.168.1.102:88;
        }
2)wrr         
              ,         ,weight        ,                。
        upstream backend {
            server 192.168.1.101 weight=1;
            server 192.168.1.102 weight=2;
            server 192.168.1.103 weight=3;
        }
3)ip_hash  (upstream_fair)      
                ip( Nginx           IP) hash    ,           
       ,    session    。
        upstream backend {
            ip_hash;
            server 192.168.1.101:81;
            server 192.168.1.102:82;
            server 192.168.1.103:83;
        }
 :   ip_hash ,         weight backup
4)fair    (    hash  )      
        fair    ,               (rt)     ,      rt        
     。
        upstream backend {
            server 192.168.1.101;
            server 192.168.1.102;
            fair;
        }
5)url_hash
         ip_hash  ,      url hash       ,    url           ,   
               。
        upstream backend {
            server 192.168.1.101;
            server 192.168.1.102;
            hash $request_uri;
            hash_method crc32;
        }
upstream
down:                         
backup:                LVS Sorry Server,     backup      
max_fails:                 ,   1
fail_timeout:          max_fails    ,       
              [vip: 10.0.0.11]

        [LB1 Nginx]         [LB2 Nginx]
        10.0.0.20           10.0.0.21

          web1     web2              phpserver1     phpserver2
    10.0.0.22      10.0.0.23           10.0.0.24       10.0.0.24
           :
    :
    # yum install nginx php php-fpm -y
    # vim /etc/nginx/nginx.conf   //  php  
     server        :
    location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
   
     php-fpm       php-fpm   :    9000  
   #vim /etc/php-fpm.d/www.conf  //      ,    apache
   user = nginx
   group = nginx
   
         nginx:
         nginx.conf      nginx
   
   # systemctl start php-fpm
       

  nginx       :
upstream web {
    server 10.0.0.22 weight=1 max_fails=2 fail_timeout=2;
        server 10.0.0.23 max_fails=2 fail_timeout=5 down;
        }
upstream phpserver {
    server 10.0.0.24 backup;
    server 10.0.0.25;
        }       #       http  server  
       
server {
    listen 80;
        server_name www.baidu.com;
location ~* \.html${            #html   
        proxy_pass http://web;
        }

location ~* \.php$ {         #php   
        proxy_pass http://phpserver;
    proxy_set_header Host   $host;
        proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_connect_timeout 30;
    proxy_send_timeout 60;
    proxy_read_timeout 60;

    proxy_buffering on;      
    proxy_buffer_size 32k;   
    proxy_buffers 4 128k;
    proxy_busy_buffers_size 256k;
    proxy_max_temp_file_size 256k;
        }
}

좋은 웹페이지 즐겨찾기