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_read_timeout 180;
(partial) parameter description


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


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.


Default:uwsgi_buffering on
Response buffering


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.


Shared cache


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


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


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




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


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

upstream backend  {
uwsgi_pass   backend;


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


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.