我正在运行Django, FastCGI和Nginx。我正在创建一个api的种类,在那里有人可以通过XML发送一些数据,我将处理,然后返回一些状态码的每个节点被发送过来。

问题是Nginx会抛出一个504网关超时,如果我花了太长时间来处理XML——我认为超过60秒。

所以我想设置Nginx,如果任何匹配位置/api的请求都不会超时120秒。什么样的设定才能实现这一点呢?

到目前为止,我有:

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

编辑:我有什么是不工作:)


代理超时是很好的,对于代理,不是FastCGI…

影响FastCGI超时的指令有client_header_timeout, client_body_timeout和send_timeout。

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


对于那些在unicorn和rails中使用nginx的人来说,超时很可能在unicorn中。rb文件

在unicorn.rb中设置一个较大的暂停

timeout 500

如果你仍然面临问题,尝试在nginx的上游设置fail_timeout=0,看看这是否能解决你的问题。这是为了调试目的,在生产环境中可能是危险的。

upstream foo_server {
        server 127.0.0.1:3000 fail_timeout=0;
}

如果你用独角兽。

看看你的服务器顶部。Unicorn现在可能正在使用100%的CPU。 这个问题有几个原因。

你应该检查你的HTTP请求,有些请求可能很难。 看看独角兽的版本。也许你最近更新了,有些东西坏了。


在http nginx section (/etc/nginx/nginx.conf)中添加或修改:

keepalive_timeout 300s

在服务器nginx部分(/etc/nginx/sites-available/your-config-file.com)添加这些行:

client_max_body_size 50M;
fastcgi_buffers 8 1600k;
fastcgi_buffer_size 3200k;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;

在php文件中127.0.0.1:9000 (/etc/php/7.X/fpm/pool.d/www.conf)修改:

request_terminate_timeout = 300

希望能帮到你。


在服务器代理集中

location / {

                proxy_pass http://ip:80;                

                proxy_connect_timeout   90;
                proxy_send_timeout      90;
                proxy_read_timeout      90;

            }

在服务器php中这样设置

server {
        client_body_timeout 120;
        location = /index.php {

                #include fastcgi.conf; //example
                #fastcgi_pass unix:/run/php/php7.3-fpm.sock;//example veriosn

                fastcgi_read_timeout 120s;
       }
}