nginx+tomcat 集群配置之nginx conf 配置

nginx加2台tomcat。session 没有共享。有时间把ssl配置也做以下。

以下是nginx的conf配置文件

user  nginx nginxGroup;
#nginx 启动进程数或线程数
worker_processes  1;

error_log   logs/error.log crit;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;
#打开文件个数的限制
worker_rlimit_nofile 65535;

#用google的缓存工具处理缓存
google_perftools_profiles /tmp/tcmalloc/;

events {
#高性能网络IO模型EPOLL
    use epoll;
#连接数
    worker_connections  65535;
}


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

    
    sendfile        on;
    
    keepalive_timeout  65;
 
    #gzip  on;
    
#bogon 是我的主机名字
#集群2个tomcat
    upstream bogon {
	server localhost:8081 weight=2;	
    	server localhost:8082 weight=2;
	ip_hash;
    }
#禁止通过直接ip来访问 
    server{
       server_name _;
       return 404; 	
    }	
	 	
    server {
        listen       80;
        server_name  bogon;
	index index.html inex.htm index.jsp;
        charset utf-8;
#nginx的web目录
	root	/home/nginx/tomcats/files;
	#server_names_hash_bucket_size 128;
	client_header_buffer_size 32k;
	large_client_header_buffers 4 32k;
	client_max_body_size 8m;
        #access_log  logs/host.access.log  main;

        location / {
            
	    client_max_body_size 100m;		
        }
	
	location ~^/(WEB-INF)/{
	     deny all;	
	}
#tomcat 处理 jsp请求	
	location ~ .*.jsp$ {
	    proxy_set_header Host $http_host; 
            proxy_redirect     off; 
            proxy_pass         http://bogon; 
            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|html)$ {
    	     expires 30d;
	} 
	
	location ~ .*\.(js|css)?$ {
	    expires 1h;    
	}
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

      

       
    }


    

}

你可能感兴趣的:(nginx.conf)