How do I prevent a Gateway Timeout with FastCGI on Nginx

后端 未结 5 430
旧时难觅i
旧时难觅i 2020-11-27 09:04

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

相关标签:
5条回答
  • 2020-11-27 09:41

    For those using nginx with unicorn and rails, most likely the timeout is in your unicorn.rb file

    put a large timeout in unicorn.rb

    timeout 500
    

    if you're still facing issues, try having fail_timeout=0 in your upstream in nginx and see if this fixes your issue. This is for debugging purposes and might be dangerous in a production environment.

    upstream foo_server {
            server 127.0.0.1:3000 fail_timeout=0;
    }
    
    0 讨论(0)
  • 2020-11-27 09:44

    In http nginx section (/etc/nginx/nginx.conf) add or modify:

    keepalive_timeout 300s
    

    In server nginx section (/etc/nginx/sites-available/your-config-file.com) add these lines:

    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;
    

    In php file in the case 127.0.0.1:9000 (/etc/php/7.X/fpm/pool.d/www.conf) modify:

    request_terminate_timeout = 300
    

    I hope help you.

    0 讨论(0)
  • 2020-11-27 09:45

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

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

    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.

    HTH.

    0 讨论(0)
  • 2020-11-27 09:48

    If you use unicorn.

    Look at top on your server. Unicorn likely is using 100% of CPU right now. There are several reasons of this problem.

    • You should check your HTTP requests, some of their can be very hard.

    • Check unicorn's version. May be you've updated it recently, and something was broken.

    0 讨论(0)
  • 2020-11-27 10:02

    In server proxy set like that

    location / {
    
                    proxy_pass http://ip:80;                
    
                    proxy_connect_timeout   90;
                    proxy_send_timeout      90;
                    proxy_read_timeout      90;
    
                }
    

    In server php set like that

    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;
           }
    }
    
    0 讨论(0)
提交回复
热议问题