django - 无法在皇帝模式下使用 ini 文件运行 uwsgi - 权限被拒绝

标签 django nginx uwsgi

我无法使用我的 ini 文件在 emperror 模式下运行 uwsgi。我已经使用 sudo pip install uwsgi 安装了 uwsgi。
当我尝试启动 uwsgi 时,出现错误:

sudo /etc/init.d/uwsgi start
/etc/init.d/uwsgi: line 72: /usr/share/uwsgi/init/snippets: No such file or directory
/etc/init.d/uwsgi: line 73: /usr/share/uwsgi/init/do_command: No such file or directory
[....] Starting app server(s): uwsgi/etc/init.d/uwsgi: line 80: do_command: command not found
 failed!

我正在使用 Debian。首先我尝试关注django and nginx docs ,但是当它不起作用时,我用谷歌搜索了很多。 这是我的 ebook_uwsgi.ini 文件:

# ebook_uwsgi.ini file
[uwsgi]
emperor = /etc/uwsgi/vassals
#plugins        = python #if uwsgi installed with pip, dont have to use this line
# Django-related settings
# the base directory (full path)
chdir           = /var/www/django/ebook/ebook/wsgi/ebook/
# Django's wsgi file
module          = controller.wsgi:application
# the virtualenv (full path)
home            = /var/www/django/ebook

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 10

# the socket (use the full path to be safe
socket         = /var/uwsgi/ebook.sock
# ... with appropriate permissions - may be needed
chmod-socket    = 664
uid             = www-data
gid             = www-data
# clear environment on exit
vacuum          = true


no-site         = True
wsgi-file       = /var/www/django/ebook/ebook/wsgi/ebook/controller/wsgi.py
env             = DJANGO_SETTINGS_MODULE=controller.settings # set an environment variable

这是我的 ebook_nginx.conf:

# mysite_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    server unix:///var/uwsgi/ebook.sock; # for a file socket
    #server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen      8001;
    # the domain name it will serve for
    server_name IP #.bookdownloading.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 /var/www/django/ebook/ebook/data;  # your Django project's media files - amend as required
    }

    location /static {
        alias /var/www/django/ebook/ebook/wsgi/static/; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        include     /var/www/django/ebook/ebook/uwsgi_params; # the uwsgi_params file you installed
    }
}

其中IP代表服务器真实IP。 当我用我的 ini 文件启动 uwgi 时,我得到权限被拒绝:

uwsgi --ini ebook_uwsgi.ini 
[uWSGI] getting INI configuration from ebook_uwsgi.ini
*** Starting uWSGI 2.0.10 (64bit) on [Tue Apr 14 17:11:32 2015] ***
compiled with version: 4.7.2 on 14 April 2015 16:47:40
os: Linux-2.6.32-042stab104.1 #1 SMP Thu Jan 29 12:58:41 MSK 2015
nodename: zoltan
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 8
current working directory: /var/www/django/ebook/ebook
detected binary path: /usr/local/bin/uwsgi
chdir() to /var/www/django/ebook/ebook/wsgi/ebook/
your processes number limit is 2062113
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
*** starting uWSGI Emperor ***
bind(): Permission denied [core/socket.c line 230]

我在/var/uwsgi/ebook.sock 中使用 socked,我已将 www-data 设置为 uwsgi 目录的所有者:

ls -la /var
total 128
drwxr-xr-x 13 root     root     15 apr 14 16:29 .
drwxr-xr-x 23 root     root     23 apr 12 19:46 ..
drwxr-xr-x  2 root     root     19 apr 13 06:25 backups
...
drwxr-xr-x  2 www-data www-data  2 apr 14 16:36 uwsgi

为什么我的权限被拒绝?
//编辑: 我缺少一些配置设置。这是我的新 ini 文件:

# ebook_uwsgi.ini file
[uwsgi]
#emperor = /etc/uwsgi/vassals
#plugins        = python #if uwsgi installed with pip, dont have to use this line
# Django-related settings
# the base directory (full path)
chdir           = /var/www/django/ebook/ebook/wsgi/ebook/
# Django's wsgi file
module          = controller.wsgi:application
# the virtualenv (full path)
home            = /var/www/django/ebook

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 1

# the socket (use the full path to be safe
socket         = /var/uwsgi/ebook.sock
# ... with appropriate permissions - may be needed
chmod-socket    = 664
uid             = www-data
gid             = www-data
# clear environment on exit
vacuum          = true


no-site         = True
wsgi-file       = /var/www/django/ebook/ebook/wsgi/ebook/controller/wsgi.py
#env             = DJANGO_SETTINGS_MODULE=controller.settings # set an environment variable

和 nginx 设置:

# mysite_nginx.conf

# the upstream component nginx needs to connect to
upstream ebook {
    server unix:///var/uwsgi/ebook.sock; # for a file socket
    #server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen      8001 default_server;
    # the domain name it will serve for
    server_name IP; #.bookdownloading.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 /var/www/django/ebook/ebook/data;  # your Django project's media files - amend as required
    }

    location /static {
        alias /var/www/django/ebook/ebook/wsgi/static/; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass      ebook;
        include         /var/www/django/ebook/ebook/uwsgi_params; # the uwsgi_params file you installed
    }
}

无论我是否运行 uwsgi,我都会收到 502 Bad Gateway。 nginx 错误日志:

2015/05/12 16:22:08 [crit] 3002#0: *1 connect() to unix:///var/uwsgi/ebook.sock failed (13: Permission denied) while connecting to upstream, client: 78.45.37.119, server: IP, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///var/uwsgi/ebook.sock:", host: "IP:8001"

嗯,尽管我已将 stocket 文件的所有者设置为 www-data,但它是作为我的用户创建的,nginx 无法读取它。

最佳答案

我已阅读您的帖子,您遇到权限问题,因为可能 www-data 对文件夹 uwsgi 没有写入权限,您有两个测试方法:

  1. 使用 www-data 用户登录并尝试在 /var/uwsgi/内创建文件
    • 使用 www-data 用户 su - www-data 登录
  2. 将文件夹权限更改为 775 (chmod 775/var/uwsgi/)
<小时/>

另一个选择是尝试将套接字的路径更改为 tmp 文件夹。我使用 tmp 文件夹在虚拟机中尝试了您的配置,它运行良好

ebook_uwsgi.ini:

socket = /tmp/ebook.sock

ebook_nginx.conf:

upstream django {
    server unix:///tmp/ebook.sock;
}

关于django - 无法在皇帝模式下使用 ini 文件运行 uwsgi - 权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29631136/

相关文章:

nginx - 如果我删除了/etc/nginx 文件夹(Ubuntu 14.04),如何重新安装 nginx?

python - 在 docker 容器中使用 uwsgi 和 nginx 设置 Flask 应用程序

NGINX + uWSGI 连接被对等方重置

python - virtualenvs 应该去哪里生产?

python - 我应该把 models.py 放在 Django 的什么地方?

python - 使用 python-social-auth 在数据库中预先注册用户

python - 在django中使用id作为url有什么解决方案吗?

reactjs - Next.js 应用程序在生产中频繁重新加载

node.js - Meteor 忘记密码邮件不发送

python - nginx + uwsgi 502 Bad Gateway python