Question

UWSGI made response but NGINX return empty response.

Posted March 2, 2021 1.5k views
NginxPythonAPIPython FrameworksFlask

My other api endpoints are working fine but only a file upload specific api endpoint is not working.

i’m using Flask for API development, along with nginx and uwsgi.

UWSGI LOG

[pid: 107416|app: 0|req: 1/2] 106.78.35.202 () {44 vars in 886 bytes} [Tue Mar  2 05:54:26 2021] POST /api/file_upload => generated 296 bytes in 5876 msecs (HTTP/1.1 200) 3 headers in 104 bytes (4 switches on core 0)

NGINX LOG

2021/03/02 05:59:32 [error] 107686#107686: *2 upstream timed out (110: Connection timed out) while reading upstream, client: ***.**.**.***, server: ***.***.**.***, request: "POST /api/file_upload HTTP/1.1", upstream: "uwsgi://unix:/var/www/vocal/vocal.sock:", host: "***.***.**.***"

Nginx config file.

server {

    listen 80;
    server_name ***.***.**.***;

    root /var/www/vocal/;
    access_log              /var/log/nginx/vocal_access.log;
    error_log               /var/log/nginx/vocal_error_log;

    uwsgi_read_timeout      300s;
    uwsgi_send_timeout      300s;
    proxy_read_timeout  300s;


    location / {

        include         uwsgi_params;
        uwsgi_pass      unix:/var/www/vocal/vocal.sock;     

    client_max_body_size    15M;
       # proxy_pass     unix:/var/www/vocal/vocal.sock;
    proxy_redirect      off;
        proxy_set_header    Host $host;
        proxy_set_header    X-Real-IP $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Host $server_name;
    proxy_read_timeout  300;
    }

    location /output {
        autoindex on;
        alias           /var/www/vocal/output/;
    sendfile            on;
    #sendfile_max_chunk     15m;
    proxy_read_timeout      300;
    }

    location /upload {
        autoindex on;
        alias           /var/www/vocal/app/main/file_upload/upload/;
    sendfile            on;
        #sendfile_max_chunk     15m;
    proxy_read_timeout      300;
    }

}

uwsgi file config.

[uwsgi]
module = wsgi:application

master = true
processes = 10

socket = vocal.sock
#socket = 127.0.0.1:5000
chmod-socket = 660
vacuum = true

die-on-term = true

logto = /var/log/uwsgi/%n.log

#protocol = uwsgi
harakiri = 120

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi there,

As far as I can see the backend service is handling the request for around 6 seconds or so, however, the proxy_read_timeout inside your location / is set to 300 without an s at the end which I believe defaults to milliseconds.

I could suggest either changing it to 3600 for example or adding an s: 300s.

Let me know how it goes!
Regards,
Bobby

  • hello @bobbyiliev
    Thank you for looking into this issue.

    I could suggest either changing it to 3600 for example or adding an s: 300s.
    

    i made above changes but still i’m having same error.

    2021/03/05 08:44:40 [error] 133590#133590: *546 upstream timed out (110: Connection timed out) while reading upstream, client: ***, server: 157.245.12.135, request: "POST /api/file_upload HTTP/1.1", upstream: "uwsgi://unix:/var/www/vocal/vocal.sock:", host: "157.245.12.135"
    
    
    • Hi there,

      Do you get the error straight away or does it wait for 300s before you see the error?

      You could try increasing the timeout for UWSGI as well: http-timeout = 300.

      Regards,
      Bobby

      • @bobbyiliev

        UWSGI LOG

        [pid: 161705|app: 0|req: 1/2] 42.111.117.173 () {44 vars in 886 bytes} [Sun Mar  7 11:28:14 2021] POST /api/file_upload => generated 296 bytes in 6188 msecs (HTTP/1.1 200) 3 headers in 104 bytes (4 switches on core 0)
        

        getting no response in Nginx error log as well as on postman side too.

        New USWGI file

        [uwsgi]
        module = wsgi:application
        
        master = true
        processes = 10
        
        #socket = vocal.sock
        #socket = 127.0.0.1:5000
        chmod-socket = 660
        vacuum = true
        
        die-on-term = true
        
        logto = /var/log/uwsgi/%n.log
        
        #protocol = uwsgi
        #harakiri = 120
        
        http = 0.0.0.0:5000
        http-to = vocal.sock
        http-timeout = 300
        
        

        NEW Nginx file

        server {
        
            listen 80;
            server_name 157.245.12.135;
        
            root /var/www/vocal/;
            access_log              /var/log/nginx/vocal_access.log;
            error_log               /var/log/nginx/vocal_error_log;
        
            uwsgi_read_timeout      3600;
            uwsgi_send_timeout      3600;
            proxy_read_timeout  3600;
            #socket-timeout     3600;
        
        
            location / {
        
                include         uwsgi_params;
                uwsgi_pass      unix:/var/www/vocal/vocal.sock;     
        
            client_max_body_size    15M;
               # proxy_pass     unix:/var/www/vocal/vocal.sock;
            proxy_redirect      off;
                proxy_set_header    Host $host;
                proxy_set_header    X-Real-IP $remote_addr;
                proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header    X-Forwarded-Host $server_name;
            proxy_read_timeout  3600;
            }
            location /output {
                autoindex on;
                alias           /var/www/vocal/output/;
            sendfile            on;
            #sendfile_max_chunk     15m;
            proxy_read_timeout       3600;
            }
        
            location /upload {
                autoindex on;
                alias           /var/www/vocal/app/main/file_upload/upload/;
            sendfile            on;
                #sendfile_max_chunk     15m;
            proxy_read_timeout     3600;
            }
        
        }