django - nginx+uwsgi启动提示unknown directive "location /"(新手)

【字号: 日期:2022-08-18浏览:15作者:雯心

问题描述

p.s: 环境是ubuntu16.04,项目的目录是/home/alps/mysite

# uwsgi启动正常uwsgi -i uwsgi.ini

/home/alps/mysite/uwsgi.ini配置文件如下

[uwsgi]socket = 127.0.0.1:8001chdir=/home/alps/mysite/wsgi-file = mysite/wsgi.pyprocesses = 2threads = 4chmod-socket = 664

/etc/nginx/sites-enabled/mysite.conf的配置文件如下

server{ location/ {listen80;uwsgi_pass127.0.0.1:8001include/etc/nginx/uwsgi_params; }}

下面是报错信息

$ sudo service nginx configtest * Testing nginx configuration [fail] $ systemctl restart nginx.serviceJob 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:2nginx: configuration file /etc/nginx/nginx.conf test failednginx.service: Control process exited, code=exited status=1Failed 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:19月 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 然后看转发能不能过来

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

相关文章: