加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

用nginx和uWSGI提供django

发布时间:2020-12-13 21:41:29 所属栏目:Nginx 来源:网络整理
导读:我跟着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; charse

我跟着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;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读