使用Nginx与django和uwsgi的麻烦 [英] Trouble with using Nginx with django and uwsgi

查看:163
本文介绍了使用Nginx与django和uwsgi的麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照 http://uwsgi-docs.readthedocs中的步骤操作.org / en / latest / tutorials / Django_and_nginx.html 但是当所有步骤完成时没有任何错误我访问127.0.0.1:8000,它响应超时,我的nginx日志显示

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


上游超时(110:连接超时),同时从上游读取响应标题

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

顺便说一句,我可以访问127.0.0.1:8001,其中uwsgi和django运行良好。
我也可以访问127.0.0.1:8000/image/1.jpg中的图像,但是只能访问127.0.0.1:8000

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

这是我的nginx.conf

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;
    }
}

我使用 uwsgi - http 127.0.0.1:8001 --chdir = mysite --module = mysite.wsgi
运行uwsgi。我在 https中使用 uwsgi_params 主机://github.com/nginx/nginx/blob/master/conf/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

推荐答案

uWSGI有2与Web服务器通信的协议。其中之一是正常的HTTP协议,也可以直接与客户端通信。但是还有一些特殊的uwsgi协议,针对HTTP代理服务器和uWSGI之间的通信进行了优化。

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.

当使用 uwsgi_pass

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

如果你用 - http param启动uWSGI,uWSGI将使用HTTP协议(这就是你在做什么),但是如果nginx仍在使用 uwsgi_pass 它希望在该套接字上使用uWSGI协议,而不是HTTP。

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.

要修复它,您必须更改uwsgi start命令要使用 - 套接字而不是 - http (这是推荐的方式,但您将无法检查如果您在浏览器中直接输入 127.0.0.8001 ,那么uWSGI是否正常工作,但是如果您的命令与 - http 正常工作,使用 - socket )或使用 proxy_pass 而不是您的nginx配置中的 uwsgi_pass

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.

在链接中描述了您被提及的权限, a href =http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html#nginx-and-uwsgi-and-test-py =nofollow> here

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

这篇关于使用Nginx与django和uwsgi的麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆