Nginx timeouts when uWSGI takes long to process request

前端 未结 4 1312
暗喜
暗喜 2021-01-31 15:05

I have Nginx + uWSGI for Python Django app.

I have the following in my nginx.conf:

location / {
    include uwsgi_params;
    uwsgi_pass            


        
相关标签:
4条回答
  • 2021-01-31 15:36

    Solved by changing the following Nginx config

    proxy_connect_timeout 300;
    proxy_read_timeout    300;
    
    
    client_body_timeout   300;
    client_header_timeout 300;
    keepalive_timeout     300;
    

    And UWSGI setting

    http-timeout = 300 // or 'socket-timeout = 300' depending on uwsgi setting
    
    0 讨论(0)
  • 2021-01-31 15:44

    Looking at the uwsgi error logs and understanding what the problem has helped me. Issue was not related to Nginx configurations at all. My email host has changed and the code threw error while calling the send email code

    0 讨论(0)
  • 2021-01-31 15:46

    The configuration that solves the problem is:

    location / {
        include uwsgi_params;
        uwsgi_pass   127.0.0.1:9001;
        uwsgi_read_timeout 300;
        index  index.html index.htm;
    }
    

    The reason the above configuration in the question did not work for us because unfortunately in our machine multiple paths had nginx.conf file. We were working with the conf at the wrong path.

    To correctly figure out which path your nginx is picking up the configuration from run:

    nginx -V  # V is caps
    

    this will have a --conf-path=[] which will tell you exactly from where it is picking up the configuration from.

    I recently found the above nginx -V to not give the right info. I will leave the above just in case others find it useful.

    0 讨论(0)
  • 2021-01-31 15:49

    In addition to the "uwsgi_read_timeout" answer, you should also check that ownership is correct for your nginx uwsgi cache directory. Ownership must be set to the same user as the running nginx process... In my case I had to do this

    grep '^user' /etc/nginx/nginx.conf
    ls -lah /var/cache/nginx/uwsgi_temp
    for f in $( find /var/cache/nginx/uwsgi_temp ); do ls -lah $f; done
    

    Are these files owned by the same user? If not, you could shut down nginx and remove all the cache files, make sure that the proper owner is on /var/cache/nginx/uwsgi_temp and restart. Maybe you could also just do a recursive chown, I didn't test this approach.

    # store the user
    THEUSER=$(grep '^user' /etc/nginx/nginx.conf | sed 's/.* //; s/;.*//' )
    

    Remove cache and restart approach

    /etc/init.d/nginx stop
    rm -rf /var/cache/nginx/uwsgi_temp/* 
    chown $THEUSER:$THEUSER /var/cache/nginx/uwsgi_temp
    /etc/init.d/nginx start
    

    Recursive chown approach

    chown -R $THEUSER:$THEGROUP /var/cache/nginx/uwsgi_temp/
    # not sure if you have to restart nginx here... 
    
    0 讨论(0)
提交回复
热议问题