开发者社区> 问答> 正文

Nginx Timeout的问题,使用的Tomcat - tomcat报错

Nginx的error日志为:


2015/09/16 13:07:22 [error] 2144#4008: *556 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 221.237.157.69, server: cms.caitb.com, request: "GET /cms/ HTTP/1.1", upstream: "http://[::1]:8081/cms/", host: "cms.caitb.com"

完全不知道怎么回事了,Nginx转发到Tomcat这个过程非常缓慢,长达1.5min以上,可以用上面的域名访问测试下。

相关配置参数:

server {
        listen       80;
        server_name  cms.caitb.com;
		
		location ~ .*\.(htm|html|gif|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma|woff|jpg)$ {   #设置静态网页直接由nginx进行处理
			root D:/APP/apache-tomcat-8.0.26-8081/webapps;
			expires 30d;
		}
		
		location ~ .*\.(js|css)?$ {
			root D:/APP/apache-tomcat-8.0.26-8081/webapps;
			expires 1h;
		}
		
		
        location / {
            proxy_pass http://localhost:8081;
			
			proxy_redirect          off;
			proxy_set_header        Host $host;
			client_max_body_size    10m;
			client_body_buffer_size 128k;
			proxy_connect_timeout   90;
			proxy_send_timeout      150;
			proxy_read_timeout      150;
			proxy_buffer_size       16k;
			proxy_buffers           4 64k;
			proxy_busy_buffers_size 128k;
			proxy_temp_file_write_size 128k;
		  
        }
    }



展开
收起
montos 2020-05-31 08:52:01 692 0
1 条回答
写回答
取消 提交回答
  • proxy_pass http://localhost:8081;

    localhost 换成IP试试

    ######多谢哥们,真是一语道破天机啊,确实快很多啊。能解释下什么原因呢?######
    proxy_connect_timeout 300;
    proxy_read_timeout 300;
    proxy_send_timeout 300;
    proxy_buffer_size 64k;
    proxy_buffers   4 32k;
    proxy_busy_buffers_size 64k;
    proxy_temp_file_write_size 64k;

    值调大点试试。

    proxy_redirect          off;
    proxy_set_header        Host $host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;



    把这个也加上吧,没全部代理过去。

    2020-05-31 08:52:15
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
《Nginx 代理系统常用手册》 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载