如何增加 NGINX 的超时时间?

Ada*_*ike 7 python wsgi nginx flask

我正在使用 Python、Flask、uWSGI 和 NGINX 来托管 Web 服务器。其中一个功能涉及为用户生成一个文件,这可能需要一两分钟。在此操作中,我不断收到来自 NGINX 的 504 超时。我试图改变一些配置变量/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;
Run Code Online (Sandbox Code Playgroud)

然后我重新加载systemctl reload nginx但它没有改变任何东西。

如何增加请求超时前的时间长度?谢谢你的帮助

小智 6

在“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;
}
Run Code Online (Sandbox Code Playgroud)

来源: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


Emm*_*uel 1

我遇到了同样的问题..我找到了一种解决方法,告诉 nginx 接受一定数量的数据而不是默认数据。不是尝试管理超时本身,而是改变事务中接受的数据量就达到了目的。

 server {

        client_max_body_size            5M; # or more ^^

}
Run Code Online (Sandbox Code Playgroud)

但这确实不是一个安全的选择..它有效,但要小心这样做。

此外,如果您使用反向代理 WSGI 网关(例如 Php)..底层机制可能优先于该网关