【问题标题】:upstream timed out (110: Connection timed out) while reading response header from upstream从上游读取响应标头时上游超时(110:连接超时)
【发布时间】:2018-10-15 19:49:24
【问题描述】:

我是 nginx 服务器的新手。我目前面临的问题是从 iOS 应用程序拨打电话后连接超时问题。我收到的 Json 很大,因此服务器上记录了超时。

还检查了在 stackoverflow 上发布的各种答案。但没有帮到我。

下面是我的访问日志和错误日志。请帮忙。

错误日志

upstream timed out (110: Connection timed out) while reading response header from upstream, client: xxxxxxxxxxx, server: xxxxxxxxxxx, request: "POST /api/event/gallery HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock", host: "xxxxxxxxxxx"

访问日志

"POST /api/event/gallery HTTP/1.1" 504 192 "-" "mysite/2 CFNetwork/889.9 Darwin/16.7.0"

nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    client_max_body_size 50M;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

【问题讨论】:

    标签: php amazon-web-services nginx laravel-5.1 amazon-elb


    【解决方案1】:

    更新

    在检查此问题时,我增加了 \etc\php\7.0\fpm\pool.d\www.conf 中的时间设置 -request_terminate_timeout 并遇到 HTTP 状态代码 499。 访问日志

    "POST /api/event/gallery HTTP/1.1" 499 0 "-" "mysite/2 CFNetwork/889.9 Darwin/16.7.0"
    

    所以我开始调查这个问题,发现有负载均衡器 (AWS ELB),它有一个默认为 60 秒的超时设置。推荐https://www.cadence-labs.com/2017/07/fix-nginx-timeout-499-client-closed-request/

    在那里增加超时(ELB)后,我设法在邮递员中得到了结果。但事实证明它非常不稳定。这意味着我会在 4-5 次尝试后得到一次响应。

    所以我设法添加了一些设置 等\nginx\站点可用\默认 在每个服务器和位置块中添加了以下设置。

    fastcgi_read_timeout 540;
    proxy_connect_timeout 3000s;
    proxy_send_timeout   3000;
    proxy_read_timeout   3000;
    

    并重新启动 nginx。

    这解决了这个问题。但是我还是觉得响应的时间比较长,性能还没有达到可以接受的水平。

    也非常欢迎以更好的方式解决此问题的任何建议/cmets/suggestions。

    【讨论】:

      【解决方案2】:

      我想补充一点,我通过搜索得到了这个问题,我的根本原因是一个错误导致我的应用程序代码中出现无限循环,而 nginx 正在等待返回。

      如果您正在阅读此页面,因为以前快速返回此错误,那么问题在于您的上游尝试执行的操作而不是 nginx。

      【讨论】:

        猜你喜欢
        • 2013-09-15
        • 1970-01-01
        • 1970-01-01
        • 2018-05-19
        • 1970-01-01
        • 2021-06-01
        • 2017-04-01
        • 2014-03-01
        • 2011-08-01
        相关资源
        最近更新 更多