Flask Uwsgi nginx:504 Gateway Time Out

Source: Internet
Author: User



The Uwsgi+nginx deployed Web site runtime may produce errors such as 504 Gateway time out, due to improper setting of the relevant parameters.






Nginx and Uwsgi integration with three parameters can be used to set the time-out period, in the Nginx configuration file http->server->location set.


Uwsgi_connect_timeout: The default is 60 seconds, and the timeout for the Uwsgi-server connection cannot exceed 75 seconds. Disconnect attempts if the connection is unsuccessful during the timeout period.
uwsgi_read_timeout: Default 60 seconds, Nginx waits for the UWSGI process to send the response data time-out. This parameter needs to be increased if there is a uwsgi process that needs to run for a long time to produce output results. If you see upstream timed out in the error log file, you need to increase this parameter. Nginx closes the connection if it has not received a response over the timeout period.
uwsgi_send_timeout: Default 60 seconds, Nginx sends request time-out to the UWSGI process. The time-out period is calculated from the interval of two write operations, not the entire request. If the timeout period is exceeded, the connection will be closed if the action is not written.

In addition, UWSGI itself has a parameter Harakiri (configured in Uwsgi.xml or Uwsgi.ini), and if each request takes more than that value, the request is discarded and the corresponding worker is retracted.


Specification of common parameters of Nginx Uwsgi module





Uwsgi under the Nginx


Official documents


Actual configuration (/etc/nginx/nginx.conf)


In this example, only 3 parameters are used


server {
        listen   5000;
        server_name localhost; if ( $request_method !~ ^(GET|HEAD|POST)$ ) { return 403;
        }

        location / {
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:3031;
        uwsgi_read_timeout 180;
        }
}
(partial) parameter description


Uwsgi_bind



Default:none
Binds an IP address that Uwsgi communicates with the outside world through the address of the binding.



Uwsgi_buffer_size



Default:uwsgi_buffer_size 4k/8k
The size of the read buffer, by default, is equivalent to uwsgi_buffers, but it can be set smaller.



Uwsgi_buffering



Default:uwsgi_buffering on
Response buffering



Uwsgi_buffers



Default:uwsgi_buffers 8 4k/8k
Set the number and size of read buffers, default is 8, 4k, which is used to cache the answer from the UWSGI service.



Uwsgi_cache



Default:off
Shared cache



Uwsgi_connect_timeout



Default:uwsgi_connect_timeout 60
Timeout for connecting Uwsgi-server, no more than 75 seconds



Uwsgi_ignore_client_abort



Default:uwsgi_ignore_client_abort off
Ignores the terminating response returned by Uwsgi-server.



Uwsgi_modifier1



default:0
Set the first modifier for the UWSGI request, which is the WSGI request by default. (??)



Uwsgi_modifier2



default:0



Uwsgi_param



Default:none
Specifies Uwsgi-server, which can be strings, variables, or combinations of them.



Uwsgi_pass



Default:none
Specify the IP address and port of the uwsgi-server, or the socket file
Or define a load balancer


upstream backend  {
  server 192.168.0.1:3031;
  server 192.168.0.2:3031;
}
 
uwsgi_pass   backend;


Uwsgi_read_timeout



Default:uwsgi_read_timeout 60
Sets a time-out period to wait for Uwsgi to return data.



Uwsgi_send_timeout



Default:uwsgi_send_timeout 60
Set a time-out for a request to Uwsgi






This article is from the "Intelligent Future _XFICC" blog, please be sure to keep this source http://xficc.blog.51cto.com/1189288/1676649



Flask Uwsgi nginx:504 Gateway Time Out


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.