简体   繁体   English

如何增加 NGINX 的超时时间?

[英]How to increase timeout for NGINX?

I am using Python, Flask, uWSGI and NGINX to host a web server.我正在使用 Python、Flask、uWSGI 和 NGINX 来托管 Web 服务器。 One of the functions involves generating a file for the user which can take up to a minute or two.其中一个功能涉及为用户生成一个文件,这可能需要一两分钟。 On this action I keep getting a 504 timeout from NGINX.在此操作中,我不断收到来自 NGINX 的 504 超时。 I tried to change some config variables in /etc/nginx/nginx.conf like keepalive_timeout but that didn't work.I also tried to add the following to /etc/nginx/conf.d/timeout.conf :我尝试更改/etc/nginx/nginx.conf一些配置变量,例如keepalive_timeout但这不起作用。我还尝试将以下内容添加到/etc/nginx/conf.d/timeout.conf

proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;

and then I reloaded with systemctl reload nginx but it didn't change anything.然后我用systemctl reload nginx重新加载,但它没有改变任何东西。

How do I increase the length of time before the request times out?如何增加请求超时前的时间长度? Thanks for any help谢谢你的帮助

Add the following directives at the end of the 'http' section to increase the timeout limit to 180 seconds (3 minutes):在“http”部分的末尾添加以下指令以将超时限制增加到 180 秒(3 分钟):

http {
    <...>
    include /etc/nginx/conf.d/.conf;

    proxy_send_timeout 180s;
    proxy_read_timeout 180s;
    fastcgi_send_timeout 180s;
    fastcgi_read_timeout 180s;
}

Source : https://support.plesk.com/hc/en-us/articles/115000170354-An-operation-or-a-script-that-takes-more-than-60-seconds-to-complete-fails-on-a-website-hosted-in-Plesk-nginx-504-Gateway-Time-out来源: https : //support.plesk.com/hc/en-us/articles/115000170354-An-operation-or-a-script-that-takes-more-than-60-seconds-to-complete-fails- on-a-website-hosted-in-Plesk-nginx-504-Gateway-Time-out

I faced the same problem .. I've found a workaround telling nginx to accept a certain amount of data over the default one.我遇到了同样的问题..我找到了一种解决方法,告诉 nginx 接受一定数量的数据而不是默认数据。 Not trying to manage the timeout itself but changing the amount of data accepted in the transaction did the trick.不是试图管理超时本身,而是改变事务中接受的数据量就成功了。

 server {

        client_max_body_size            5M; # or more ^^

}

but it's really not a secured option .. it works, but take care doing this.但它真的不是一个安全的选择......它有效,但要小心这样做。

moreover if you are using a reverse proxy WSGI gateway (Php for example) .. the underlayrer mechanism may take precedence over that此外,如果您使用反向代理 WSGI 网关(例如 Php).. 底层机制可能优先于那个

server {

        server_name                     yourhost;
        client_max_body_size            5M;

        location / {
                proxy_http_version      1.1;
                proxy_set_header        Host $host;
                proxy_set_header        Upgrade $http_upgrade;
                proxy_set_header        Connection "upgrade";
                proxy_set_header        X-Real-IP       $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

                proxy_pass              http://127.0.0.1:8080; # depending on your network conf

        }
}

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

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