http {
keepalive_timeout 1800s; #指定 KeepAlive 的超时时间(timeout)。指定每个 TCP 连接最多可以保持多长时间。Nginx 的默认值是 75 秒,有些浏览器最多只保持 60 秒,所以可以设定为 60 秒。若将它设置为 0,就禁止了 keepalive 连接。
proxy_connect_timeout 1800s; #nginx跟后端服务器连接超时时间(代理连接超时)
proxy_send_timeout 1800s; #后端服务器数据回传时间(代理发送超时)
proxy_read_timeout 1800s; #连接成功后,后端服务器响应时间(代理接收超时)
fastcgi_connect_timeout 1800s; #指定nginx与后端fastcgi server连接超时时间
fastcgi_send_timeout 1800s; #指定nginx向后端传送请求超时时间(指已完成两次握手后向fastcgi传送请求超时时间)
fastcgi_read_timeout 1800s; #指定nginx向后端传送响应超时时间(指已完成两次握手后向fastcgi传送响应超时时间)

}

浏览器debug 调试一打开 Nginx 就 504 Gateway Time-out_gateway



http {
include mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $request_time $upstream_response_time ';

access_log logs/access.log main;

client_header_buffer_size 64k;
large_client_header_buffers 8 64k;
client_max_body_size 200m;
client_body_buffer_size 8M;

#清理缓存
sendfile off;

# sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 1200;
proxy_connect_timeout 50000;
#proxy_connect_timeout 500;
proxy_read_timeout 60000;
#proxy_send_timeout 500;
proxy_send_timeout 50000;
#fastcgi_buffers 80 128k;

fastcgi_connect_timeout 30000;
fastcgi_send_timeout 30000;
fastcgi_read_timeout 30000;

send_timeout 6000;
proxy_buffer_size 96k;
#proxy_buffer_size 16k;
proxy_buffers 4 64k;
#proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_temp_path /data/nginx/proxy_temp;
proxy_cache_path /data/nginx/proxy_cache levels=1:2 keys_zone=content:20m inactive=1d max_size=100m;
proxy_cache_bypass $http_secret_header;

gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml application/javascript;

浏览器debug 调试一打开 Nginx 就 504 Gateway Time-out_504_02

最重要的六条配置:

proxy_connect_timeout 1800s; #nginx跟后端服务器连接超时时间(代理连接超时)
proxy_send_timeout 1800s; #后端服务器数据回传时间(代理发送超时)
proxy_read_timeout 1800s; #连接成功后,后端服务器响应时间(代理接收超时)
fastcgi_connect_timeout 1800s; #指定nginx与后端fastcgi server连接超时时间
fastcgi_send_timeout 1800s; #指定nginx向后端传送请求超时时间(指已完成两次握手后向fastcgi传送请求超时时间)
fastcgi_read_timeout 1800s; #指定nginx向后端传送响应超时时间(指已完成两次握手后向fastcgi传送响应超时时间)