无法更改 NGINX 超时

Jef*_*eff 6 configuration nginx timeout

我在我的Nginx服务器上得到一个504超时: 504 Gateway Time-out。该网站允许用户下载自定义数据文件。该站点在大多数情况下都可以正常运行,用户可以毫无问题地下载一些文件。问题是数据文件仅在请求时生成。因此,当请求复杂数据时,Python 后端需要一分钟以上的时间来生成文件并开始下载。因为一分钟内没有响应 Nginx 返回一个504 Gateway Time-out. 文件本身是 CSV 文件并且不是很大,因此在后端生成文件后下载速度很快,但我需要一种方法让 Nginx 等待更长时间。

我正在寻找一种将 Nginx 超时从 1 分钟增加到大约 10 分钟的方法。

到目前为止,我已经尝试过:

更改nginx.conf文件以在http {}大括号之间包含以下行

uwsgi_connect_timeout 75s;
proxy_connect_timeout 600;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;
Run Code Online (Sandbox Code Playgroud)

我还尝试按照https://asdqwe.n​​et/blog/solutions-504-gateway-timeout-nginx/ 的建议添加timeout.conf文件:/etc/nginx/conf.d/

proxy_connect_timeout       600;
proxy_send_timeout          600;
proxy_read_timeout          600;
send_timeout                600; 
Run Code Online (Sandbox Code Playgroud)

每次更改后,我都重新启动了服务器,但 1 分钟后仍然发生超时。这已经通过curl -o在服务器上运行 a来绕过任何服务提供商问题进行了进一步测试。输出如下。

$curl -o out-put-file.csv "./localhost/my/url"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   183   100   183   0    0       3      0  0:01:01  0:01:00  0:00:01    48
Run Code Online (Sandbox Code Playgroud)

这个错误被写入到 error.log

2018/03/26 09:55:15 [error] 10105#10105: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 142.1.2.3, server: localhost, request: "GET /my/url", upstream: "uwsgi://unix:/tmp/my-applacation.sock", host: "142.1.2.3"
Run Code Online (Sandbox Code Playgroud)

当我在没有 Nginx 的情况下运行我的应用程序并运行相同curl -o的请求时,请求需要很长时间(根据请求的数据最多 8 分钟),但它确实正确完成,没有错误或超时。


运行$ /usr/sbin/nginx -V 2>&1 | grep conf显示配置文件位于--conf-path=/etc/nginx/nginx.conf


Nginx 版本:nginx/1.12.2 和 nginx/1.4.6 (Ubuntu)

操作系统版本:Ubuntu 16.04.1 和 Ubuntu 14.04.5 LTS


编辑:

我已经测试过更改配置文件中的 worker_processes 数量只是为了确保配置文件中其他内容的更改确实被选中,并且确实更改该数字会更改工作人员的数量,因此文件是正确的文件并更改为被 Nginx 接走。只是没有更改超时(或者可能是完整的 http 部分?)。我还测试了将超时设置为 30 秒,但它们仍然在 1 分钟时超时。此外,尝试将这些设置放入sites-enabled/my_site但我仍然得到相同的结果。

编辑2:

据我所知,我正在根据 Nginx 文档设置正确的值。 uwsgi_connect_timeout

ngx_http_proxy_module

Jef*_*eff 5

我解决了!!

结果发现问题与uwsgi有关,而我已经设置了

uwsgi_connect_timeout 75s;
Run Code Online (Sandbox Code Playgroud)

我实际上需要设置的是

uwsgi_read_timeout 600s;
Run Code Online (Sandbox Code Playgroud)