Nginx 出现504 Gateway Time-out的解决方法
nginx代理报504超时错误。
问题处理:
1、修改/etc/nginx/nginx.conf,添加如下信息:
复制代码
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
client_max_body_size 1024m;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
gzip_min_length 1k;
gzip_comp_level 9;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
#解决nginx 504错误
proxy_connect_timeout 300; #单位秒
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
# ps:以timeout结尾配置项时间要配置大点
}
2、修改server{},添加如下信息:
location / {
proxy_pass http://ip:80/;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}