繁体   English   中英

uWSGI,nginx,django unix套接字不起作用

[英]uWSGI, nginx, django unix sockets not working

我有一个django应用程序。 我似乎无法让Nginx正确提供静态文件,但这不是这个问题。

当前的问题是,遵循本指南时: https : //gist.github.com/evildmp/3094281

我尝试使用Unix套接字而不是Web套接字。

例如

server unix:///tmp/uwsgi.sock;    # for a file socket
#server 127.0.0.1:8001;      # for a web port socket

使用/tmp/uwsgi.sock套接字而不是127.0.0.1:8001 Web端口套接字。

问题是,当我使用Web端口套接字并导航到domainname.com:8001时,我到达了uWSGI所服务的网站,但是没有加载任何静态文件。 因此,这意味着至少uwsgi正在运行。 但是当我切换到文件套接字时,我什至无法使它正常工作。

我究竟做错了什么?

这是我的nginx.conf:

# nginx.conf
upstream django {
    # connect to this socket
    # server unix:///tmp/uwsgi.sock;    # for a file socket (TRYING TO USE)
    server 127.0.0.1:8001;      # for a web port socket (RATHER THAN THIS)
    }

server {
    # the port your site will be served on
    listen      8000;
    # the domain name it will serve for
    server_name .cshenkan.com;   # substitute your machine's IP address or FQDN
    charset     utf-8;

    #Max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
            alias /home/ubuntu/sasite-rewrite/media;      # your Django pro$
    }

    location /static {
            alias /home/ubuntu/sasite-rewrite/static;     # your Django pro$
    }
    location /assets  {
            alias /home/ubuntu/sasite-rewrite/assets
    } 

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /etc/nginx/uwsgi_params; # or the uwsgi_params you installe$
        }
    }

还有我的base.py设置文件片段:

STATIC_ROOT = normpath(join(SITE_ROOT, 'static'))
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    normpath(join(SITE_ROOT, 'static')),
    normpath(join(SITE_ROOT, 'assets')),
)

以及使用网络套接字时如何运行uwsgi:

uwsgi --http:8001 --chdir / home / ubuntu / sasite-rewrite --wsgi文件/home/ubuntu/sasite-rewrite/sasite/wsgi.py

以及在使用unix套接字时如何运行它:

uwsgi --socket /tmp/uwsgi.sock --chdir / home / ubutnu / sasite-rewrite --wsgi-file /home/ubuntu/sasite-rewrite/sasite/wsgi.py

使用unix套接字时,我似乎无法使其正常工作。

我也无法让Nginx提供正确的静态文件,例如,如果我将文件添加到名为1.png或1.txt的媒体目录中,并尝试使用domainname.com:8000/media/1.png访问它们,我总是从服务器错误得到挂起或无响应。

我究竟做错了什么?

如何使Unix套接字正常工作? 我使用的命令正确吗?

我也不明白这一点,当我使用Web套接字时,我可以连接到domainname.com:8001并获得没有静态文件的页面,它看起来像废话,但是从uwsgi加载的。 但是对于unix套接字,我不知道如何访问uwsgi服务的页面以查看它是否可以与unix套接字一起使用。 在继续使用nginx之前,我需要解决此问题,因为我尝试将Web套接字与nginx结合使用,但在那里仍然没有运气,我希望Unix套接字设置正确后,nginx会更好地工作。

您有什么建议或示例吗? 非常感谢,我是django的程序员,但是我很少自己部署这些站点。 所以我真的在这里挣扎。

非常感谢任何帮助,谢谢。

今天,对于uwsgi协议,NGINX + Socket Unix存在相同的问题。 我发现NGINX的1.8版存在问题。

尝试安装将通过UNIX SOCKET运行的1.10版本。

如果使用open-SuSE,则可以在此处获得rpm:

http://download.opensuse.org/repositories/home:/ghostlyrat/openSUSE_Leap_42.2/x86_64/nginx-1.10.1-3.3.x86_64.rpm

或者,直接在官方的nginx下载区域中:

http://nginx.org/en/download.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM