服务器 A :192.168.65.102   服务器 B :192.168.65.103   服务器 C :192.168.65.104


一、确认 102、103、104 已存在Nginx,102已开启Nginx



二、修改 102 nginx.conf 配置文件

注意:proxy_pass 参数需要对应 upstream 的名称   
三、修改 103 和 104 服务器的 nginc.conf    
  1. #102 加入
  2. upstream luwen02.com2{ 
  3.         server 192.168.65.103; 
  4.         server 192.168.65.104; 
  5. server { 
  6.         listen 192.168.65.102:80; 
  7.         server_name 192.168.65.102; 
  8.  
  9.         location / { 
  10.                 proxy_set_header        Host $host; 
  11.                 proxy_set_header        X-Real-IP $remote_addr; 
  12.                 proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for; 
  13.                 client_max_body_size    32m; 
  14.                 client_body_buffer_size 256k; 
  15.                 proxy_pass http://luwen02.com2; 
  16.         } 
  17.         access_log  /var/log/nginx/nginx-access.log; 
  18. }
  19.  
    #103 / 104修改
  1. server 
  2.     listen       80 default
  3.     server_name  192.168.65.102; 
  4.     index index.html index.htm index.php;
  5.     root  /data/httpd/;
  6.     location ~ .*\.php.* 
  7.     { 
  8.         include php_fcgi.conf; 
  9.         include pathinfo.conf; 
  10.     } 
  11.     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ 
  12.     { 
  13.         expires      30d; 
  14.     } 
  15.     location ~ .*\.(js|css)?$ 
  16.     { 
  17.         expires      1h; 
  18.     } 
  19.     access_log /var/log/nginx/access.log; 
  20.     #access_log off
  21. }
注意:server_name 必须指向负载均衡分配的服务器地址上。也就是102这台服务器。    
四、分别检查 102、103、104 配置文件 /usr/local/nginx/sbin/nginx -t
五、分别重启 102、103、104 nginx 服务器 /etc/init.d/nginx restart 
六、访问 192.168.65.102 的 index.html