[英]Why nginx is returning error 504 timeout even if in my nginx.conf all the properties are setted
user www-data;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 500;
types_hash_max_size 2048;
server_names_hash_bucket_size 64;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
include /usr/local/ispmgr/etc/nginx.domain;
log_format isp '$bytes_sent $request_length';
server {
client_header_timeout 10m;
client_body_timeout 10m;
send_timeout 10m;
fastcgi_read_timeout 10m;
fastcgi_send_timeout 900;
proxy_read_timeout 500;
proxy_connect_timeout 500;
client_max_body_size 500m;
server_name mysite.com www.mysite.com;
listen MY_IP_ADRESS;
disable_symlinks if_not_owner from=$root_path;
set $root_path /var/www/mysite/data/www/mysite.com;
location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
root $root_path;
access_log /var/www/nginx-logs/mysite isp;
access_log /var/www/httpd-logs/mysite.com.access.log ;
error_page 404 = @fallback;
}
location / {
proxy_pass http://MY_IP_ADRESS:81;
proxy_redirect http://MY_IP_ADRESS:81/ /;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
location ~* ^/(webstat|awstats|webmail|myadmin|pgadmin)/ {
proxy_pass http://MY_IP_ADRESS:81;
proxy_redirect http://MY_IP_ADRESS:81/ /;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
location @fallback {
proxy_pass http://MY_IP_ADRESS:81;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
location ^~ /webstat/ {
auth_basic "Restricted area";
auth_basic_user_file /var/www/mysite/data/etc/68420649.passwd;
try_files $uri @fallback;
}
include /usr/local/ispmgr/etc/nginx.inc;
}
server {
server_name shop.mysite.com www.shop.mysite.com;
listen MY_IP_ADRESS;
charset UTF-8;
disable_symlinks if_not_owner from=$root_path;
set $root_path /var/www/mysite/data/www/shop.mysite.com;
location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
root $root_path;
access_log /var/www/nginx-logs/mysite isp;
access_log /var/www/httpd-logs/shop.mysite.com.access.log ;
error_page 404 = @fallback;
}
location / {
proxy_pass http://MY_IP_ADRESS:81;
proxy_redirect http://MY_IP_ADRESS:81/ /;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
location ~* ^/(webstat|awstats|webmail|myadmin|pgadmin)/ {
proxy_pass http://MY_IP_ADRESS:81;
proxy_redirect http://MY_IP_ADRESS:81/ /;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
location @fallback {
proxy_pass http://MY_IP_ADRESS:81;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
location ^~ /webstat/ {
auth_basic "Restricted area";
auth_basic_user_file /var/www/mysite/data/etc/68813297.passwd;
try_files $uri @fallback;
}
include /usr/local/ispmgr/etc/nginx.inc;
}
server {
server_name loto.mysite.com www.loto.mysite.com;
listen MY_IP_ADRESS;
charset UTF-8;
disable_symlinks if_not_owner from=$root_path;
set $root_path /var/www/mysite/data/www/loto.mysite.com;
location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
root $root_path;
access_log /var/www/nginx-logs/mysite isp;
access_log /var/www/httpd-logs/loto.mysite.com.access.log ;
error_page 404 = @fallback;
}
location / {
proxy_pass http://MY_IP_ADRESS:81;
proxy_redirect http://MY_IP_ADRESS:81/ /;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
location ~* ^/(webstat|awstats|webmail|myadmin|pgadmin)/ {
proxy_pass http://MY_IP_ADRESS:81;
proxy_redirect http://MY_IP_ADRESS:81/ /;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
location @fallback {
proxy_pass http://MY_IP_ADRESS:81;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
location ^~ /webstat/ {
auth_basic "Restricted area";
auth_basic_user_file /var/www/mysite/data/etc/68813303.passwd;
try_files $uri @fallback;
}
include /usr/local/ispmgr/etc/nginx.inc;
}
}
在这里,我已经放置了所有我找到的配置,但是在上传大约20 MB的文件(不到2分钟)时,仍然收到504超时错误,您可以查看这些设置并告诉我我所缺少的吗?,完成所有操作后,我已重新启动服务器,但没有帮助,请帮助! 我无法上传文件
更新
您需要在location
范围中配置fastcgi_read_timeout
。
location {
...
fastcgi_read_timeout 900s; # 15 minutes
...
}
同样,您可以清理配置(这是可选的)的是,您可以将所有proxy_set_headers以及超时信息放入例如/etc/nginx/fastcgi_settings
:
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
fastcgi_read_timeout 900s;
然后,您可以删除所有proxy_set_header
这样就不必重复它们,而是将其替换为它们:
include /etc/nginx/fastcgi_settings
这将使您的配置更易于维护。
老回答这些变量必须在定义server
范围,而不是在http
范围。 另外,如果您要代理php,则还需要设置
proxy_read_timeout 120;
proxy_connect_timeout 120;
如果仍有问题,请提供完整的配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.