1
votes

I follow the steps in http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html but when all the steps done without any error I visit 127.0.0.1:8000, it response with a time-out, my nginx log shows that

upstream timed out (110: Connection timed out) while reading response header from upstream,

By the way, I can access 127.0.0.1:8001 where uwsgi and django works well. And I can access image in 127.0.0.1:8000/image/1.jpg as well, but just cannot access 127.0.0.1:8000

here's my nginx.conf

upstream django {
    server 127.0.0.1:8001;
}

server {
    listen 8000;
    server_name 127.0.0.1
    charset utf-8;

    client_max_body_size 75M;

    location /media {
        alias /home/zhaolei/virtualdjango/bin/mysite/media;
    }

    location /image {
        alias /home/zhaolei/virtualdjango/bin/mysite/image;
    }

    location / {
        uwsgi_pass django;
        include /home/zhaolei/virtualdjango/bin/mysite/uwsgi_params;
    }
}

I use uwsgi --http 127.0.0.1:8001 --chdir=mysite --module=mysite.wsgi to run uwsgi. I use uwsgi_params hosts in https://github.com/nginx/nginx/blob/master/conf/uwsgi_params

1

1 Answers

3
votes

uWSGI have 2 protocols to communicate with web server. One of them is normal HTTP protocol, that can also be used to communicate directly with clients. But there is also special uwsgi protocol, optimized for communication between HTTP Proxy server and uWSGI.

That protocol is used by nginx when using uwsgi_pass directive, and by uWSGI when you're starting your uWSGI server with --socket param.

If you're starting uWSGI with --http param, uWSGI will use HTTP protocol (that is what you're doing), but if nginx is still using uwsgi_pass it's expecting uWSGI protocol on that socket, not HTTP.

To fix it you have to either change your uwsgi start command to use --socket instead of --http (that's recommended way, but you won't be able to check if uWSGI is functioning properly by entering 127.0.0.8001 directly in your browser, but that's okay: if your command with --http worked properly, there won't be any difference using --socket) or use proxy_pass instead of uwsgi_pass in your nginx config.

And it's described on link that you're mentioned, right here