随笔-179  评论-666  文章-29  trackbacks-0
阿里云服务器优惠券

花了一个上午的时间研究nginx+tomcat的负载均衡测试,集群环境搭建比较顺利,但是session同步的问题折腾了几个小时才搞定,现把我的过程贴上来,以备用。
软件及环境是:
虚拟机上装centos 5.5
IP为:192.168.0.51 装上nginx和tomcat  6.0.32 命名为 Tomcat1
一台win7上装tomcat  6.0.32  IP为:192.168.0.50  命名为 Tomcat2

首先装nginx,我是参照http://blog.s135.com/nginx_php_v6/ 配了一个Nginx + PHP(FastCGI)环境,然后再加上Tomcat的转发。
我的nginx.conf 修改如下
#######################################################################
#
# This is the main Nginx configuration file.  
#
# More information about the configuration options is available on 
#   
* the English wiki - http://wiki.nginx.org/Main
#   * the Russian documentation - http://sysoev.ru/nginx/
#
#######################################################################

#
----------------------------------------------------------------------
# Main Module 
- directives that cover basic functionality
#
#   http:
//wiki.nginx.org/NginxHttpMainModule
#
#
----------------------------------------------------------------------

user              nginx;
worker_processes  
8;

error_log  
/var/log/nginx/error.log;
#error_log  
/var/log/nginx/error.log  notice;
#error_log  
/var/log/nginx/error.log  info;

pid        
/var/run/nginx.pid;


#
----------------------------------------------------------------------
# Events Module 
#
#   http:
//wiki.nginx.org/NginxHttpEventsModule
#
#
----------------------------------------------------------------------

events 
{
    worker_connections  
10240;
}



#
----------------------------------------------------------------------
# HTTP Core Module
#
#   http:
//wiki.nginx.org/NginxHttpCoreModule 
#
#
----------------------------------------------------------------------

http 
{
    include       
/etc/nginx/mime.types;
    default_type  application
/octet-stream;

    log_format  main  
'$remote_addr - $remote_user [$time_local] "$request" '
                      
'$status $body_bytes_sent "$http_referer" '
                      
'"$http_user_agent" "$http_x_forwarded_for"';

    access_log  
/var/log/nginx/access.log  main;

server_names_hash_bucket_size  
128;
client_header_buffer_size  32k;
large_client_header_buffers  
4  32K;
client_max_body_size 8m;


    sendfile        on;
    tcp_nopush     on;

    #keepalive_timeout  
0;
    keepalive_timeout  
65;

    #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  tserver  
{
        server   
192.168.0.51:8080 weight=1;
        server   
192.168.0.50:8080 weight=1;
 }

    
    #
    # The 
default server
    #
    server 
{
        listen       
80;
        server_name  _;

        #charset koi8
-r;

        #access_log  logs
/host.access.log  main;

         location 
~ .*\.(php|php5)?$
        
{
          root  
/www/ROOT;      
          #fastcgi_pass  unix:
/tmp/php-cgi.sock;
         fastcgi_pass  
127.0.0.1:9000;
         fastcgi_index index.php;
         include fcgi.conf;
        }


        location 
~ \.(jsp|jspx|do|htm)?{
         proxy_set_header  Host $host;  
         proxy_set_header  X
-Real-IP  $remote_addr;
         proxy_pass http:
//tserver;#转向tomcat处理       
        }


        location 
~ (/dwr/)? {
         proxy_set_header  Host $host;
         proxy_set_header  X
-Real-IP  $remote_addr;
         proxy_pass http:
//tserver;#转向tomcat处理
        }



        location 
/ {
            root   
/www/ROOT;
            index  index.html index.jsp 
default.jsp index.do default.do;
        }


        error_page  
404              /404.html;
        location 
= /404.html {
            root   
/www/ROOT;
        }


        # redirect server error pages to the 
static page /50x.html
        #
        error_page   
500 502 503 504  /50x.html;
        location 
= /50x.html {
            root   
/www/ROOT;
        }


        # proxy the PHP scripts to Apache listening on 
127.0.0.1:80
        #