从上游读取响应标头时,上游超时(110:连接超时) - php

我是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;
#   }
#}

参考方案

更新资料

在检查此问题时,我增加了\ 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次尝试中得到一次回复。

所以我设法在
etc \ nginx \ sites-available \ default
在每个服务器和位置块的以下设置中添加了该设置。

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

并重新启动了nginx。

这解决了问题。但是我仍然认为,响应所花费的时间太长,性能还不能令人满意。

同样,也欢迎任何以更好的方式解决此问题的建议/评论/建议。

PHP:获取调用引用的数组名称 - php

假定以下函数并调用:function doSomething( &$someArray ) { // Do something to $someArray } $names=array("John", "Paul", "George", "Ringo"); doSomet…

PHP-MySQL结果转换为JSON - php

我试图了解如何将MySQL结果转换为JSON格式,以便以后可以在Javascript中使用此JSON来构建HTML表。但是我的代码只是产生大量的空值,我还不明白为什么。$result = mysqli_query($con, "SELECT * FROM Customers"); $test = json_encode($result);…

PHP Count数组元素 - php

嗨,有人可以解释为什么这会返回“数组由0个元素组成”。 :$arr = array(1,3,5); $count = count($arr); if ($count = 0) { echo "An array is empty."; } else { echo "An array has $count elements.…

PHP:从函数返回值并直接回显它? - php

这可能是一个愚蠢的问题,但是……的PHPfunction get_info() { $something = "test"; return $something; } html<div class="test"><?php echo get_info(); ?></div> 有没有办…

PHP:将数据从二维数组复制到一维数组的最快方法 - php

我有一个巨大的二维PHP数组,带有500万行。$t = [ [ "id" => 1, "name" => "foo" ], [ "id" => 2, "name" => "bar" ] ]; 现在,我必须将此数组的I…