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呢?
You can clearly see a problem
Your configuration does not even pass nginx's own configuration verification, which means there is something wrong with your nginx configuration.
Then I saw that your configuration included
You can be sure that the error is because of your nginx configuration /etc/nginx/sites-enabled/mysite.conf
I think you need to check your configuration again, don’t rush to use supervisor. If your forwarding configuration has startup problems, It has nothing to do with supervisor at all.
I suggest you follow this idea,
First, modify the configuration correctly. I see that your nginx conf is configured to forward unix:///tmp/mysite.sock; your uwsgi configuration does not specify a socket to listen to a certain port. Now I think you can try to set it up. The socket parameter of uwsgi listens to a certain port, for example
Then change nginx’s forwarding uwsgi_pass unix:///tmp/mysite.sock; to
uwsgi_pass 127.0.0.1:8001
Then go to uwsgi -i uwsgi.ini and see if the forwarding can come over
If this is successful, the error you are reporting now should be solved. Look at the back