Python nginx.service:无法从文件 /run/nginx.pid 读取 PID:参数无效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42078674/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument
提问by user61629
I'm working through https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu-16-04. I've completed the tut but I'm getting a 502 error.
我正在通过https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu-16-04工作。我已经完成了 tut 但我收到了 502 错误。
My nginx server block configuration file:
我的 nginx 服务器块配置文件:
server {
listen 80;
server_name 198..xxx.xxx.xxx mysite.org;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/deploy/mysite3;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/run/uwsgi/mysite3.sock;
}
}
deploy@server:/etc/nginx/sites-enabled$ sudo systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2017-02-06 17:30:53 EST; 4s ago
Process: 7374 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
Process: 7383 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 7380 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 7384 (nginx)
CGroup: /system.slice/nginx.service
├─7384 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
└─7385 nginx: worker process
Feb 06 17:30:53 server systemd[1]: Starting A high performance web server and a reverse proxy server...
Feb 06 17:30:53 server systemd[1]: nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument
Feb 06 17:30:53 server systemd[1]: Started A high performance web server and a reverse proxy server.
nginx error log shows:
nginx 错误日志显示:
2017/02/06 21:10:32 [error] 7385#7385: *15 upstream prematurely closed connection while reading response header from upstream, client: 64.xxx.xxx.xxx, server: 198.xxx.xxx.xxx, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/run/uwsgi/mysite3.sock:", host: "mysite.org"
It looks to me that uwsgi is running ok:
在我看来,uwsgi 运行正常:
Feb 06 17:43:42 server uwsgi[7434]: WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0xc7ac10 pid: 7435 (default app)
Feb 06 17:43:42 server uwsgi[7434]: *** uWSGI is running in multiple interpreter mode ***
Feb 06 17:43:42 server uwsgi[7434]: spawned uWSGI master process (pid: 7435)
Feb 06 17:43:42 server uwsgi[7434]: Mon Feb 6 17:43:42 2017 - [emperor] vassal mysite3.ini has been spawned
Feb 06 17:43:42 server uwsgi[7434]: spawned uWSGI worker 1 (pid: 7439, cores: 1)
Feb 06 17:43:42 server uwsgi[7434]: spawned uWSGI worker 2 (pid: 7440, cores: 1)
Feb 06 17:43:42 server uwsgi[7434]: spawned uWSGI worker 3 (pid: 7441, cores: 1)
Feb 06 17:43:42 server uwsgi[7434]: spawned uWSGI worker 4 (pid: 7442, cores: 1)
Feb 06 17:43:42 server uwsgi[7434]: spawned uWSGI worker 5 (pid: 7443, cores: 1)
Feb 06 17:43:42 server uwsgi[7434]: Mon Feb 6 17:43:42 2017 - [emperor] vassal mysite3.ini is ready to accept requests
How can I fix this?
我怎样才能解决这个问题?
edit:
编辑:
root@server:~# mkdir /etc/systemd/system/nginx.service.d
root@server:~# printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" > /etc/systemd/system/nginx.service.d/override.conf
root@server:~# systemctl daemon-reload
root@server:~# systemctl restart nginx
root@server:~# systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en
Drop-In: /etc/systemd/system/nginx.service.d
└─override.conf
Active: active (running) since Tue 2017-02-07 08:18:26 EST; 6s ago
Process: 10076 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5
Process: 10084 ExecStartPost=/bin/sleep 0.1 (code=exited, status=0/SUCCESS)
Process: 10082 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (cod
Process: 10079 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process
Main PID: 10083 (nginx)
CGroup: /system.slice/nginx.service
├─10083 nginx: master process /usr/sbin/nginx -g daemon on; master_pr
└─10085 nginx: worker process
Feb 07 08:18:26 server systemd[1]: Starting A high performance web server and a
Feb 07 08:18:26 server systemd[1]: Started A high performance web server and a r
root@server:~#
回答by Bogdan Stoica
That warning with the nginx.pid file is a know bug (at least for Ubutnu if not for other distros as well). More details here: https://bugs.launchpad.net/ubuntu/+source/nginx/+bug/1581864
nginx.pid 文件的警告是一个已知错误(至少对于 Ubutnu 而言,如果不是对于其他发行版也是如此)。更多细节在这里:https: //bugs.launchpad.net/ubuntu/+source/nginx/+bug/1581864
Workaround (on a ssh console, as root, use the commands bellow):
解决方法(在 ssh 控制台上,以 root 身份使用以下命令):
mkdir /etc/systemd/system/nginx.service.d
printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" > /etc/systemd/system/nginx.service.d/override.conf
systemctl daemon-reload
systemctl restart nginx
Then check if you still see that nginx.pid error and also if nginx is actually running and if you can connect to port 80 on your server.
然后检查您是否仍然看到 nginx.pid 错误,以及 nginx 是否实际运行,以及您是否可以连接到服务器上的端口 80。
I would also check if this actually exists and the permissions on it:
我还会检查这是否确实存在及其权限:
/run/uwsgi/mysite3.sock
If nginx is running and uWSGI is running as well then I guess it's a configuration problem
如果 nginx 正在运行并且 uWSGI 也在运行,那么我想这是一个配置问题
I understand you want to use Django so I would recommend to review your actual configuration and compare it with the one from here:
我了解您想使用 Django,因此我建议您查看您的实际配置并将其与此处的配置进行比较:
http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
I hope it helps!
我希望它有帮助!