用nginx和uWSGI提供django

前端之家收集整理的这篇文章主要介绍了用nginx和uWSGI提供django前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我跟着this post去服务我的django项目.该项目与manage.py runserver运行良好,我想将其设置为生产.这是我的设置文件

Nginx.conf:

upstream django {
    server /tmp/vc.sock;
    #server 10.9.1.137:8002;
}

server {
    listen      8001;
    server_name 10.9.1.137;
    charset     utf-8;
    client_max_body_size 25M;

    location /media  {
        alias /home/deploy/vc/media;
    }
    location /static {
        alias /home/deploy/vc/static;
    }


    location / {
        uwsgi_pass  django;
        include     /etc/Nginx/uwsgi_params;
    }
}

uwsgi.ini:

[uwsgi]

chdir           = /home/deploy/vc
wsgi-file      = vc/wsgi.py

master          = true
processes       = 2
#socket          = :8002
socket          = /tmp/vc.sock
chmod-socket    = 666
vacuum          = true

如果我使用TCP端口套接字(服务器10.9.1.137:8002和套接字=:8002),它会没事的.但是,如果我将它们注释掉并使用Unix套接字(服务器/tmp/vc.sock和socket = /tmp/vc.sock),服务器将返回502错误.我应该怎么解决

这是运行/etc/init.d/Nginx restart时的Nginx错误日志

Nginx: [emerg] invalid host in upstream "/tmp/vc.sock" in /etc/Nginx/conf.d/vc.conf:2
Nginx: configuration file /etc/Nginx/Nginx.conf test Failed

当我运行uwsgi –ini vc / uwsgi.ini时,这是警告:

*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 

我不能以root身份运行uWSGI吗?

最佳答案
使用Unix域套接字的upstream server必须声明为:

upstream django {
    server unix:/tmp/vc.sock;

是的,我想你可以以root身份运行uWSGI,但是you absolutely positively should not.这是安全性101. uWSGI项目甚至可以到call it common sense

Common sense: do not run uWSGI instances as root. You can start your uWSGIs as root,but be sure to drop privileges with the uid and gid options.

顺便说一下,你的服务器块可以使用root指令.这可以让你摆脱静态资产的那些毫无意义的冗余位置.

    root /home/deploy/vc;
原文链接:https://www.f2er.com/nginx/435725.html

猜你在找的Nginx相关文章