使用nginx做反向代理,当一个tomcat断线后网页加载慢的问题

今天在window机器上布署了nginx和两个tomcat。tomcat端口分别为8080、8081,nginx可正确运行,分别在两台机器上进行负载。

但当我强制关闭某一个tomcat后,发现再刷新网页,网页处于不停的加载中,响应非常慢。开始的配置文件如下:

#user  zhaoliang;
#cpu 配置为几核
worker_processes  1;


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

#pid        logs/nginx.pid;
#最大打开文件数限制
worker_rlimit_nofile 655350;

events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

   upstream www.joery.com{
   		server 192.168.8.239:8080 weight=5;
		server 192.168.8.239:8081 weight=5;
	}
	
	
	server{
		listen 80;
		server_name www.joery.com;
		error_log /tmp/vm_err.log;
		access_log /tmp/vm_access.log;
		index login.html;
		location /{
			proxy_pass      http://www.joery.com; #http://代理名字
			client_max_body_size    10m;
			client_body_buffer_size 128k;
			proxy_read_timeout 120;
			proxy_connect_timeout 120;
			proxy_buffer_size 32k;
			proxy_buffers 4 64k;
			proxy_busy_buffers_size 128k;
			proxy_headers_hash_bucket_size 128;
			proxy_temp_file_write_size 128k;
			#用于协助JAVA代码获取外网的IP
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "upgrade";

			rewrite (.*)/(.*)_(.*)\.xyz$   $1/$2.action?$3;
			rewrite (.*)/papersurveym/MobileDefault.action_prcode=(.*)$   $1/papersurveym/MobileDefault.action?prcode=$2;
		}

		location ~ .(qqLogin|registerQQ|registerWeiBo).action$ {
		    proxy_pass http://www.joery.com;   
		}

		location ~ .(oauth2_qq).jsp$ {
			proxy_pass   http://www.joery.com;
		}

		error_page   500 502 503 504  /50x.html;
        	location = /50x.html 
                {
                        root   /usr/share/nginx/www;
                }

		#在浏览器地址输入:http://www.joery.com/NginxStatus 可以实时观察nginx读写
		#location /NginxStatus {

		#	stub_status on;
		#	access_log off;
		#	auth_basic "NginxStatus";
		#}
		
		#将符合下面表达式的请求转向到特定的代理服务器
		location ~* \.(gif|jpg|jpeg|questionStyle|kindeditor|fileupload)$ {
	         	proxy_pass      http://www.joery.com;
                }
	}
	
	
	
	
	
}

 仔细排查,发现server内的proxy_connect_timeout连接超时时间为120,修改该值为1后,再重启nginx后发现当关闭某一个tomcat后,仍可快速访问。

posted @ 2016-04-29 10:31  迟来的春天  阅读(419)  评论(0)    收藏  举报