【问题标题】:Nginx perimission denied connecting to .socketNginx 权限被拒绝连接到 .socket
【发布时间】:2018-01-05 14:21:23
【问题描述】:

尝试使用 nginx 代理 gunicorn 套接字。

/etc/systemd/system/gunicorn.service文件

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=www-data
Group=www-data
WorkingDirectory=/root/PSite/blog
ExecStart=/root/PSite/blog/blog/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/root/PSite/blog/blog.sock blog.wsgi:application

[Install]
WantedBy=multi-user.target

/etc/nginx/sites-available/blog文件

server {
    listen 80;
    server_name server_domain_or_IP;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /root/PSite/blog;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/root/PSite/blog/blog.sock;
    }
}

然后我启动守护进程:systemctl start gunicorn

运行systemctl status gunicorn 后会抛出错误:

EXEC 生成 /root/PSite/blog/blog/venv/bin/gunicorn:权限被拒绝

所有文件夹和文件归 www-data:www-data 所有。

如果我将 gunicorn 用户更改为 root 它会创建代理,但 nginx 日志显示它没有权限。

有什么问题?

【问题讨论】:

    标签: sockets nginx permissions gunicorn systemd


    【解决方案1】:

    以非 root 用户身份运行服务具有良好的安全性。但是,您通过尝试将文件存储在“/root”下使问题复杂化,该文件仅供“root”用户访问。

    尝试将您的“PSite”站点文件夹从“/root”移动到中性位置,例如“/var/www/PSite”。

    【讨论】:

      猜你喜欢
      • 2018-09-13
      • 2016-07-25
      • 1970-01-01
      • 2014-07-19
      • 2022-01-03
      • 2014-04-07
      • 2011-05-03
      • 2015-07-04
      • 2020-08-25
      相关资源
      最近更新 更多