我在错误日志中收到nginx错误,如:
[error] 4257#0: *3470 upstream timed out (110: Connection timed out) while reading response header from upstream, client 120.X.X.X
这是运行AWS的Wordpress网络服务器,并使用nginx作为反向代理。这是我的conf文件:
user nginx nginx;
worker_processes 2;
worker_rlimit_nofile 10240;
include /etc/nginx/modules.d/*.conf;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 8192;
use epoll;
accept_mutex_delay 100ms;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr $server_name $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $request_time';
log_format backend '$remote_addr $server_name $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $request_time';
log_format proxylog '$remote_addr $server_name $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $request_time '
'"$http_proxy"';
access_log /var/log/nginx/access.log main;
access_log /var/log/nginx/badactor.log proxylog if=$http_proxy;
server_name_in_redirect off;
server_tokens off;
sendfile on;
open_file_cache max=100 inactive=20s;
tcp_nopush on;
keepalive_timeout 5;
client_max_body_size 4M;
client_body_buffer_size 256k;
if_modified_since before;
gzip on;
gzip_http_version 1.0;
gzip_vary on;
gzip_comp_level 6;
gzip_types text/plain
text/xml
text/css
text/javascript
application/xhtml+xml
application/xml
application/rss+xml
application/atom_xml
application/javascript
application/x-javascript
application/x-httpd-php;
gzip_disable "MSIE [1-6]\.";
# proxy cache
proxy_cache_path /var/cache/nginx/proxy_cache levels=1:2
keys_zone=czone:32m max_size=256m inactive=1440m;
proxy_temp_path /var/cache/nginx/proxy_temp;
proxy_cache_key "$scheme://$host$request_uri";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Remote-Addr $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-UA-Detect $mobile;
proxy_set_header Accept-Encoding "";
proxy_set_header Proxy "";
proxy_hide_header X-Pingback;
proxy_hide_header Link;
proxy_hide_header ETag;
proxy_connect_timeout 5;
proxy_send_timeout 10;
proxy_read_timeout 90;
proxy_cache_use_stale timeout invalid_header http_500 http_502 http_503 http_504;
proxy_cache_lock on;
proxy_cache_lock_timeout 5s;
proxy_buffers 8 32k;
proxy_buffer_size 64k;
# fastcgi cache
#fastcgi_cache_path /var/cache/nginx/fastcgi_cache levels=1:2
# keys_zone=fastcgizone:32m inactive=60m;
#fastcgi_cache_key "$scheme$request_method$host$request_uri";
#fastcgi_cache_use_stale error timeout invalid_header http_500;
#limit_req_zone $request_method zone=method:1m rate=250r/s;
upstream backend {
server unix:/var/run/nginx-backend.sock;
}
upstream phpfpm {
server unix:/var/run/php-fpm.sock;
}
include /etc/nginx/conf.d/*.conf;
}
在客户端,收到http 502(坏网关)。可能有什么不对?
答案 0 :(得分:0)
在nginx.conf文件中,我将proxy_read_timeout值增加到300,之前设置为90.在nginx和php-fpm重启后,问题已解决。