我是 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)后,我设法在 postman 中得到结果。但事实证明它非常不稳定。这意味着我每 4-5 次尝试就会收到一次回复。
所以我设法添加一些设置 etc\nginx\sites-available\default 在每个服务器和位置 block 中添加了以下设置。
fastcgi_read_timeout 540;
proxy_connect_timeout 3000s;
proxy_send_timeout 3000;
proxy_read_timeout 3000;
并重新启动 nginx。
这解决了这个问题。但我仍然认为响应时间较长且性能未达到可接受的水平。
也非常欢迎任何以更好的方式解决此问题的建议/意见/建议。
关于php - 上游超时(110 : Connection timed out) while reading response header from upstream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50189913/