2017-01-31 28 views
0

使用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這可能是問題

+0

它在這裏,你gunicorn配置應張貼。請同時嘗試手動啓動gunicorn而不使用systemd – e4c5

+0

你能分享命令來運行 –

+0

你已經收到的答案顯示瞭如何運行它(省略了ExcecStart =部分)更新有錯誤的問題 – e4c5

回答

1

它看起來像是你的/etc/systemd/system/gunicorn.service ExecStart命令的一個問題,嘗試從命令行運行相同的命令以對其進行疑難解答。

ExecStart例如:

ExecStart=/home/user/Virtualenvs/app_virtualenv/bin/gunicorn --workers 3 --bind unix:/var/local/django/app.sock app.wsgi:application 

您可能還需要設置用戶,組和WorkingDirectory的服務:

[Service] 
User=yourAppUser 
Group=yourAppGroup 
WorkingDirectory=YourAppWD(where manage.py is located) 
ExecStart=... 
+0

已更新的問題包括服務設置 –

+0

應用程序中應該有一個名爲wsgi.py的文件dir(kb)嘗試從manage.py所在的目錄運行此命令'gunicorn --workers 3 --bind unix :kb.sock kb.wsgi:application' –

+0

你應該得到這樣的輸出:'$ gunicorn cpc.wsgi:application --bind unix:kb.sock' '[2017-01-31 14:34:38 + 0000] [5842] [INFO]啓動gunicorn 19.6.0' '[2017-01-31 14:34:38 +0000] [5842] [INFO] Listening at:unix:kb.sock(5842)' ' [2017-01-31 14:34:38 +0000] [5842] [INFO] Usin g worker:sync' '[2017-01-31 14:34:38 +0000] [5847] [INFO]啓動worker with pid:5847' –