简体   繁体   English

为什么即使在我的nginx.conf中设置了所有属性,nginx也会返回错误504超时

[英]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;
    }
}

here I've putted all the configs I cut find, but I still getting an 504 timeout error on uploading a file about 20 megabytes, its less than 2 minutes, can you look at these settings and tell me what I'am missing?, I've restarted the server after putting all this, but didn't helped, please help! 在这里,我已经放置了所有我找到的配置,但是在上传大约20 MB的文件(不到2分钟)时,仍然收到504超时错误,您可以查看这些设置并告诉我我所缺少的吗?,完成所有操作后,我已重新启动服务器,但没有帮助,请帮助! Ican't upload files 我无法上传文件

Updated 更新

You need to configure fastcgi_read_timeout in your location scopes. 您需要在location范围中配置fastcgi_read_timeout

location {
     ... 
     fastcgi_read_timeout 900s; # 15 minutes
     ...
}

Also what you can do to clean up your config (this is optional) is you can putt all the proxy_set_headers along with timeout in eg /etc/nginx/fastcgi_settings : 同样,您可以清理配置(这是可选的)的是,您可以将所有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;

Then you can remove all the proxy_set_header so you do not have to repeat them, and put this instead of them: 然后,您可以删除所有proxy_set_header这样就不必重复它们,而是将其替换为它们:

include /etc/nginx/fastcgi_settings

That will make your config easier to maintain. 这将使您的配置更易于维护。

Old Answer These variables must be defined in server scope, not in http scope. 老回答这些变量必须在定义server范围,而不是在http范围。 Also, if you are proxying to php, you also need to set 另外,如果您要代理php,则还需要设置

proxy_read_timeout 120;
proxy_connect_timeout 120;

If you are still having problems, please provide full configuration. 如果仍有问题,请提供完整的配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM