问题
Setting up django with nginx and gunicorn I've been able to have it serve static files but brings a 502 on django. The site runs okay with runserver 0.0.0.0:8000
I've also worked on uwsgi before, I don't think the two (gunicorn and uwsgi) are conflicting however.
When I run gunicorn status check I get
ubuntu@ip-172-31-16-133:~$ 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 10:36:23 UTC; 4min 20s ago
Process: 32261 ExecStart=/home/ubuntu/djangoenv/bin/gunicorn --workers 10 --bind unix:/home/ubu
Main PID: 32261 (code=exited, status=203/EXEC)
Jan 31 10:36:23 ip-172-31-16-133 systemd[1]: Started gunicorn daemon.
Jan 31 10:36:23 ip-172-31-16-133 systemd[1]: gunicorn.service: Main process exited, code=exited,
Jan 31 10:36:23 ip-172-31-16-133 systemd[1]: gunicorn.service: Unit entered failed state.
Jan 31 10:36:23 ip-172-31-16-133 systemd[1]: gunicorn.service: Failed with result 'exit-code'.
and the error log reads
2017/01/31 10:36:31 [crit] 32205#32205: *7 connect() to unix:/home/ubuntu/webapps/kenyabuzz/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 105.231.127.174, server: kenyabuzz.nation.news, request: "GET / HTTP/1.1", upstream: "http://unix:/home/ubuntu/webapps/kenyabuzz/gunicorn.socket:/", host: "kenyabuzz.nation.news"
Here's the conf file
#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;
#}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
proxy_buffering off;
proxy_pass http://app_server;
}
}
upstream app_server {
server unix:/home/ubuntu/webapps/kenyabuzz/gunicorn.socket fail_timeout=0;
}
UPDATE
Gunicorn service settings
[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
UPDATE
Running gunicorn using gunicorn kb.wsgi:application --bind 0.0.0.0:8001
returns
WSGI without exception
kb.wsgi file doesn't exist also this may be the issue
回答1:
It seems like a problem on your /etc/systemd/system/gunicorn.service ExecStart command, try runing the same command from the command line to troubleshoot it.
ExecStart example:
ExecStart=/home/user/Virtualenvs/app_virtualenv/bin/gunicorn --workers 3 --bind unix:/var/local/django/app.sock app.wsgi:application
You may need to set also the User, Group and WorkingDirectory for the service:
[Service]
User=yourAppUser
Group=yourAppGroup
WorkingDirectory=YourAppWD(where manage.py is located)
ExecStart=...
来源:https://stackoverflow.com/questions/41955530/gunicorn-django-sock-file-not-created