nginx 实现PHP应用负载均衡和动静分离 
                            
                            
IP地址规划 
                           
(1)负载均衡服务器IP地址:192.168.110.109
(2)PHP应用服务器节点1 IP地址:172.16.110.129 
(3)PHP应用服务器节点2 IP地址: 192.168.110.128
(4)静态资源文件在本地;
(5)动态PHP请求在PHP节点;
(6)使用火狐浏览器插件查看请求服务器的路径;
 
1.Nginx配置文件如下;
  include       mime.types;
  default_type  application/octet-stream;
  fastcgi_intercept_errors on;
  charset  utf-8;
  server_names_hash_bucket_size 128;
  client_header_buffer_size 4k;
  large_client_header_buffers 4 32k;
  client_max_body_size 300m;
  sendfile on;
  tcp_nopush     on;
  keepalive_timeout 60;
  tcp_nodelay on;
  client_body_buffer_size  512k;
  proxy_connect_timeout    5;
  proxy_read_timeout       60;
  proxy_send_timeout       5;
  proxy_buffer_size        16k;
  proxy_buffers            4 64k;
  proxy_busy_buffers_size 128k;
  proxy_temp_file_write_size 128k;
   
  gzip on;
  gzip_min_length  1k;
  gzip_buffers     4 16k;
  gzip_http_version 1.1;
  gzip_comp_level 2;
  gzip_types       text/plain application/x-javascript text/css application/xml;
  gzip_vary on;

     upstream  192.168.110.109 { 
        ip_hash;
            server     www.test.com  weight=1;  
            server     www.test2.com weight=1;
          }    
      upstream  css { 
       ip_hash;
          server    www.test.com   ;
          }    



    server {
        listen       80;
        server_name  192.168.110.109;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm index.php index.jsp;
            proxy_pass        http://192.168.110.109; 
            proxy_set_header  X-Real-IP  $remote_addr;  

            client_max_body_size  100m;  

        }


      location ~ \.php$ {
            proxy_pass        http://192.168.110.109;
            proxy_set_header  X-Real-IP $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header  Host $http_host;
        }
     
     1.样式请求在/home/date/style/ 下面
     
      location ~ \.(jpg|css|js|jpeg|png|bmp|ico)$ {
                               
           root  /home/data/style/;
           expires 12h;
                      
         方法二(只是反向代理)
          proxy_pass        http://css;
          proxy_set_header  X-Real-IP $remote_addr;
          proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header  Host $http_host;
        }
     
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


    }

[root@localhost conf.d]# cat /etc/hosts
    192.168.110.129  www.test.com
    192.168.110.128 www.test2.com