nginx 访问 flask 的 .sock 权限在 ubuntu16.04 中被拒绝
nginx visit flask's .sock permission denied in ubuntu16.04
如tutorial所述,我在 ubuntu16.04 中使用 flask、uwsgi 和 nginx 构建了一个项目,并得到异常 502 Bad Gateway。
查看日志发现.sock文件访问权限被拒绝
日志内容:
2018/07/24 12:38:24 [crit] 8805#8805: *1 connect() to unix:///home/mylegendarytime/final/final.sock failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///home/mylegendarytime/final/final.sock:", host: "127.0.0.1"
和我的 nginx 设置:
server {
listen 80;
server_name 127.0.0.1;
location / {
include uwsgi_params;
uwsgi_pass unix:///home/mylegendarytime/final/final.sock;
}
}
我不知道是什么错误导致了这个错误。我试过了
$ chmod 777 ~/final/final.sock
但没有任何变化
编辑:
这是我的 uWSGI 设置:
[uwsgi]
module = wsgi
master = true
processes = 5
socket = final.sock
chmod-socket = 660
vacuum = true
die-on-term = true
我尝试将 chmod-socket 更改为 777,但没有用。
这是我的 systemd unix 文件:
[Unit]
Description=uWSGI instance to serve final
After=network.target
[Service]
User=mylegendarytime
Group=www-data
WorkingDirectory=/home/mylegendarytime/final
Environment="PATH=/home/mylegendarytime/final/finalenv/bin"
ExecStart=/home/mylegendarytime/final/finalenv/bin/uwsgi --ini final.ini
[Install]
WantedBy=multi-user.target
所以我最终通过将用户更改为www-data来解决它,因为nginx使用这个名称来使用套接字。您可以在 nginx.conf.
查看
如tutorial所述,我在 ubuntu16.04 中使用 flask、uwsgi 和 nginx 构建了一个项目,并得到异常 502 Bad Gateway。 查看日志发现.sock文件访问权限被拒绝
日志内容:
2018/07/24 12:38:24 [crit] 8805#8805: *1 connect() to unix:///home/mylegendarytime/final/final.sock failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///home/mylegendarytime/final/final.sock:", host: "127.0.0.1"
和我的 nginx 设置:
server {
listen 80;
server_name 127.0.0.1;
location / {
include uwsgi_params;
uwsgi_pass unix:///home/mylegendarytime/final/final.sock;
}
}
我不知道是什么错误导致了这个错误。我试过了
$ chmod 777 ~/final/final.sock
但没有任何变化
编辑:
这是我的 uWSGI 设置:
[uwsgi]
module = wsgi
master = true
processes = 5
socket = final.sock
chmod-socket = 660
vacuum = true
die-on-term = true
我尝试将 chmod-socket 更改为 777,但没有用。
这是我的 systemd unix 文件:
[Unit]
Description=uWSGI instance to serve final
After=network.target
[Service]
User=mylegendarytime
Group=www-data
WorkingDirectory=/home/mylegendarytime/final
Environment="PATH=/home/mylegendarytime/final/finalenv/bin"
ExecStart=/home/mylegendarytime/final/finalenv/bin/uwsgi --ini final.ini
[Install]
WantedBy=multi-user.target
所以我最终通过将用户更改为www-data来解决它,因为nginx使用这个名称来使用套接字。您可以在 nginx.conf.
查看