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

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 然后看转发能不能过来

这里成功了你现在报错的问题应该就解决了。再看后面

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板