使用nginx和gunicorn設置django我已經能夠提供靜態文件,但在django上帶有502。該網站與runserver 0.0.0.0:8000
運行良好我以前也曾在uwsgi上工作過,但我認爲這兩個(gunicorn和uwsgi)是相互衝突的。Gunicorn&django sock文件未創建
當我運行gunicorn狀態檢查,我得到
[email protected]:~$ 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'.
和錯誤日誌讀取
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"
這裏的conf文件
#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服務設置
[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
使用gunicorn kb.wsgi:application --bind 0.0.0.0:8001
回報
WSGI without exception
kb.wsgi文件不也存在運行gunicorn這可能是問題
它在這裏,你gunicorn配置應張貼。請同時嘗試手動啓動gunicorn而不使用systemd – e4c5
你能分享命令來運行 –
你已經收到的答案顯示瞭如何運行它(省略了ExcecStart =部分)更新有錯誤的問題 – e4c5