Nginx upstream time out bug fix

2017/8/15 posted in  linux

问题报道

上来贴一部分日志记录,这个和前面的错误日志还是有一定的区别

2017/08/15 09:03:43 [error] 9529#0: *1090065 upstream timed out (110: Connection timed out) while connecting to upstream, client: 111.178.21.169, server: oa.hansap.com, request: "POST /fysdtdkj/uc/singleLogin.do HTTP/1.1", upstream: "http://10.11.11.164:80/fysdtdkj/uc/singleLogin.do", host: "oa.hansap.com"
2017/08/15 09:03:59 [error] 9529#0: *1088945 upstream timed out (110: Connection timed out) while connecting to upstream, client: 27.17.54.74, server: hangouweixin.hansap.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://10.11.103.17:80/favicon.ico", host: "hangouweixin.hansap.com"
2017/08/15 09:04:13 [error] 9529#0: *1090187 upstream timed out (110: Connection timed out) while connecting to upstream, client: 27.17.54.74, server: oa.hansap.com, request: "GET /fysdtdkj/j_spring_security_exit_user?j_username=admin HTTP/1.1", upstream: "http://10.11.11.164:80/fysdtdkj/j_spring_security_exit_user?j_username=admin", host: "oa.hansap.com", referrer: "http://oa.hansap.com/fysdtdkj/platform/console/main.do"
2017/08/15 09:04:26 [error] 9529#0: *1090315 upstream timed out (110: Connection timed out) while connecting to upstream, client: 27.17.54.74, server: hangouweixin.hansap.com, request: "POST /web/index.php?c=utility&a=notice& HTTP/1.1", upstream: "http://10.11.103.17:80/web/index.php?c=utility&a=notice&", host: "hangouweixin.hansap.com", referrer: "http://hangouweixin.hansap.com/web/index.php?c=account&a=display&"
2017/08/15 09:04:53 [error] 9529#0: *1089772 upstream timed out (110: Connection timed out) while connecting to upstream, client: 27.17.54.74, server: hangouweixin.hansap.com, request: "POST /web/index.php?c=account&a=display&do=package& HTTP/1.1", upstream: "http://10.11.103.17:80/web/index.php?c=account&a=display&do=package&", host: "hangouweixin.hansap.com", referrer: "http://hangouweixin.hansap.com/web/index.php?c=account&a=display&"
2017/08/15 09:05:03 [error] 9529#0: *1088945 upstream timed out (110: Connection timed out) while connecting to upstream, client: 27.17.54.74, server: hangouweixin.hansap.com, request: "GET /web/index.php?c=home&a=welcome&do=members& HTTP/1.1", upstream: "http://10.11.103.17:80/web/index.php?c=home&a=welcome&do=members&", host: "hangouweixin.hansap.com", referrer: "http://hangouweixin.hansap.com/web/index.php?c=account&a=display&"
2017/08/15 09:11:00 [error] 9529#0: *1094373 upstream timed out (110: Connection timed out) while connecting to upstream, client: 58.48.126.38, server: jhczlc.com, request: "GET / HTTP/1.1", upstream: "http://10.11.103.15:8080/", host: "www.whljyl.com"

这是贴出来的一部分日志报错,是过滤的upstream timed out (110: Connection timed out) while connecting to upstream

当前修改的方式暂时使用

  1. nginx proxy

适当的调整proxy_read_timeout值。

location / {
        ...
        proxy_read_timeout 150;
        ...
    }
  1. Upstream timed out (110: Connection timed out) while reading response header from upstream

这种情况主要在下面两种情况下发生:

a. Nginx 作为 proxy,需要适当的调整 proxy timeout 的值。

    location / {
        ...
        proxy_connect_timeout 300;
        proxy_read_timeout 300;
        proxy_send_timeout 300;
        ...
    }

b. Nginx作为 php-fpm 等其他的有上游服务,需要适当的调整 fastcgi_read_timeout 选项值

 location ~* .php$ {
        include         fastcgi_params;
        fastcgi_index   index.php;
        fastcgi_read_timeout 150;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    }
  1. open() “_usr_local_nginx_html/favicon.ico” failed (2: No such file or directory)

只需要关闭 favicon.ico 的 log:

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }