如何在 Nginx 上使用 FastCGI 防止网关超时 [英] How do I prevent a Gateway Timeout with FastCGI on Nginx

查看:22
本文介绍了如何在 Nginx 上使用 FastCGI 防止网关超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行 Django、FastCGI 和 Nginx.我正在创建一个 api,有人可以通过 XML 发送一些数据,我将处理这些数据,然后为发送的每个节点返回一些状态代码.

I am running Django, FastCGI, and Nginx. I am creating an api of sorts that where someone can send some data via XML which I will process and then return some status codes for each node that was sent over.

问题是,如果我处理 XML 的时间过长,Nginx 将抛出 504 网关超时——我认为超过 60 秒.

The problem is that Nginx will throw a 504 Gateway Time-out if I take too long to process the XML -- I think longer than 60 seconds.

所以我想设置 Nginx,以便任何与位置/api 匹配的请求都不会超时 120 秒.什么设置可以实现这一点.

So I would like to set up Nginx so that if any requests matching the location /api will not time out for 120 seconds. What setting will accomplish that.

到目前为止我所拥有的是:

What I have so far is:

    # Handles all api calls
    location ^~ /api/ {
        proxy_read_timeout 120;
        proxy_connect_timeout 120;
        fastcgi_pass 127.0.0.1:8080;
    }

我所拥有的不起作用:)

What I have is not working :)

推荐答案

代理超时很好,对于代理,而不是 FastCGI...

Proxy timeouts are well, for proxies, not for FastCGI...

影响 FastCGI 超时的指令是 client_header_timeoutclient_body_timeoutsend_timeout.

The directives that affect FastCGI timeouts are client_header_timeout, client_body_timeout and send_timeout.

编辑:考虑到 nginx wiki 上的内容,send_timeout 指令 负责设置响应的一般超时(这有点误导).对于 FastCGI,有 fastcgi_read_timeout 会影响 FastCGI 进程响应超时.

Edit: Considering what's found on nginx wiki, the send_timeout directive is responsible for setting general timeout of response (which was bit misleading). For FastCGI there's fastcgi_read_timeout which is affecting the FastCGI process response timeout.

这篇关于如何在 Nginx 上使用 FastCGI 防止网关超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆