尝试使用django和gunicorn在Nginx日志文件中设置此错误:
2017/01/31 07:04:50 [crit] 30386#30386: *1 connect() to unix:/home/ubuntu/webapps/kenyabuzz/kb.sock Failed (13: Permission denied) while connecting to upstream, client: 197.232.12.165, server: kenyabuzz.nation.news, request: "GET / HTTP/1.1", upstream: "http://unix:/home/ubuntu/webapps/kenyabuzz/kb.sock:/", host: "kenyabuzz.nation.news"
静态文件正确提供.启用了Nginx / sites的设置中的gunicorn文件
#kb gunicorn Nginx settings
server {
listen 80;
server_name kenyabuzz.nation.news;
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /home/ubuntu/webapps/kenyabuzz/kb/media; # your Django project's media files - amend as required
}
location /static {
alias /home/ubuntu/webapps/kenyabuzz/kb/static; # your Django project's static files - amend as required
}
location /favicon.ico {
alias /home/ubuntu/webapps/kenyabuzz/kb/static/kb/favicon.ico; # favicon
}
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/webapps/kenyabuzz/kb.sock;
}
}
和gunicorn设置/etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/webapps/kenyabuzz
ExecStart=/home/ubuntu/djangoenv/bin/gunicorn --workers 10 --bind unix:/home/ubuntu/kenyabuzz/kb.sock kb.wsgi:application
[Install]
WantedBy=multi-user.target
检查了gunicorn的状态
ubuntu@ip-172-31-16-133:/etc/Nginx/sites-enabled$sudo systemctl status gunicorn
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: Failed (Result: exit-code) since Tue 2017-01-31 06:59:49 UTC; 8min ago
Main PID: 30281 (code=exited, status=203/EXEC)
Jan 31 06:59:48 ip-172-31-16-133 systemd[1]: Started gunicorn daemon.
Jan 31 06:59:49 ip-172-31-16-133 systemd[1]: gunicorn.service: Main process exited, code=exited, sta
Jan 31 06:59:49 ip-172-31-16-133 systemd[1]: gunicorn.service: Unit entered Failed state.
Jan 31 06:59:49 ip-172-31-16-133 systemd[1]: gunicorn.service: Failed with result 'exit-code'.
解决方法:
您的gunicorn进程以用户Ubuntu和Group www-data运行
[Service]
User=ubuntu
Group=www-data
通常在ubuntu中,Nginx作为www-data运行.我看到你已经将www-data定义为gunicorn的组.因此你可以解决这个问题
chmod g+x /home/ubuntu/
chmod g+r /home/ubuntu/
假设您有www-data作为上述文件夹的组.如果没有,你可以改变它
sudo chgrp www-data /home/ubuntu/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。