django - nginx+uwsgi啟動提示unknown directive "location /"(新手)
迷茫
迷茫 2017-04-24 09:09:45
0
1
1240

p.s: 環境是ubuntu16.04,專案的目錄是/home/alps/mysite

# uwsgi啟動正常
uwsgi -i uwsgi.ini

/home/alps/mysite/uwsgi.ini設定檔如下

[uwsgi]
socket = 127.0.0.1:8001
chdir=/home/alps/mysite/
wsgi-file = mysite/wsgi.py

processes = 2
threads = 4

chmod-socket = 664

/etc/nginx/sites-enabled/mysite.conf的設定檔如下

server{
    location / {
        listen 80;
        uwsgi_pass 127.0.0.1:8001 
        include     /etc/nginx/uwsgi_params;
    }
}

下面是報錯訊息

$ sudo service nginx configtest
 * Testing nginx configuration [fail]

$ systemctl restart nginx.service
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

$ systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Thu 2016-09-29 19:52:25 CST; 11s ago
  Process: 3450 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)

Starting A high performance web server and a reverse proxy server...
nginx: [emerg] unknown directive "location /" in /etc/nginx/sites-enabled/mysite.conf:2
nginx: configuration file /etc/nginx/nginx.conf test failed
nginx.service: Control process exited, code=exited status=1
Failed to start A high performance web server and a reverse proxy server.
nginx.service: Unit entered failed state.
nginx.service: Failed with result 'exit-code'.

請問"location /"為什麼是unknown directive呢?

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回覆(1)
伊谢尔伦

可以很明顯的看到一個問題

9月 27 22:41:01 yue nginx[4206]: nginx: [emerg] unknown directive "server " in /etc/nginx/sites-enabled/mysite.conf:1
9月 27 22:41:01 yue nginx[4206]: nginx: configuration file /etc/nginx/nginx.conf test failed

你的配置甚至並沒有通過nginx自己的配置校驗,表示你的nginx配置就是有問題的。
然後我看到你的配置裡麵包含了

include /etc/nginx/sites-enabled/*;

可以確定報錯就是因為你nginx配置/etc/nginx/sites-enabled/mysite.conf
我覺得你需要再檢查一下你這邊的配置,先不要著急使用supervisor 如果你這個轉發配置都有啟動問題,根本跟supervisor沒關係。
我建議你按照這個思路來,

首先將配置修改正確,我看你的nginx conf裡面配置轉發的unix:///tmp/mysite.sock; 你的uwsgi配置得於此沒有指定socket監聽某個端口,現在我覺得你可以嘗試設置uwsgi的socket參數監聽某個埠例如

socket = 127.0.0.1:8001

接著將nginx的轉送uwsgi_pass unix:///tmp/mysite.sock;變成
uwsgi_pass 127.0.0.1:8001

然後去uwsgi -i uwsgi.ini 然後看轉發能不能過來

這裡成功了你現在報錯的問題應該就解決了。再看後面

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板