配置nginx.conf实现负载均衡

编辑/usr/local/nginx/conf/nginx.conf

http   
{  
          include       mime.types;  
          default_type  application/octet-stream;       
          server_names_hash_bucket_size 128;  
          client_header_buffer_size 32k;  
          large_client_header_buffers 4 32k;  
          client_max_body_size 8m;  
          sendfile on;  
          keepalive_timeout 60;  
          gzip on;  
 
#负载均衡
upstream tomcat_proxy{
          server localhost:8080 max_fails=3 weight=1 fail_timeout=60s;
          server localhost:9080 max_fails=3 weight=1 fail_timeout=60s;
        }
        
server
  {
         listen       80;
         server_name  www.abc.com;            
         index index.jsp index.php index.do index.jsp;
         access_log  logs/www.abc.com_access_nginx.log;
         error_log logs/www.abc.com_error.log;
         root  /var/www/nginx;    #nginx默认根目录
    location ~ \.(php|php5)$ {        #支持php
            fastcgi_pass  unix:/var/run/php-fpm.sock;    #php-fpm.sock模块
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
            include fastcgi_params;
            include fastcgi.conf;
            }
    location ~ \.(jsp|do)$ {        #jsp,do等页面交由tomcat处理
            proxy_pass tomcat_proxy;
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
            expires      30d;
            }
}

 

上一篇:阿里巴巴CTO王坚的 “云和互联网观”


下一篇:UpdatePanel中GridView的分页问题