今天爱分享给大家带来nginx/tengine服务器重启 /“var/run/nginx/nginx.pid” no such file or directory问题解决,希望能够帮助到大家。
环境 Centos7
问题描述:在重启虚拟机后,会删除/var/run下的文件。会杀掉进程,导致重新启动后nginx服务器无法启动。
# systemctl status nginx
>>>
● nginx.service - SYSV: nginx is a World Wide Web server. It is used to servea
Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled)
Active: active (exited) (Result: exit-code) since 二 2018-01-30 14:48:43 CST; 10min ago
Docs: man:systemd-sysv-generator(8)
Process: 2672 ExecReload=/etc/rc.d/init.d/nginx reload (code=exited, status=7)
Process: 1114 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=0/SUCCESS)
1月 30 14:48:43 bogon systemd[1]: Starting SYSV: nginx is a World Wide Web server. It is used to servea...
1月 30 14:48:43 bogon nginx[1114]: Starting nginx: [ 确定 ]
1月 30 14:48:43 bogon systemd[1]: Started SYSV: nginx is a World Wide Web server. It is used to servea.
1月 30 14:48:44 bogon nginx[1114]: nginx: [emerg] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory)
1月 30 14:50:32 bogon systemd[1]: nginx.service: control process exited, code=exited status=7
1月 30 14:50:32 bogon systemd[1]: Reload failed for SYSV: nginx is a World Wide Web server. It is used to servea.
1月 30 14:56:01 bogon systemd[1]: nginx.service: control process exited, code=exited status=7
1月 30 14:56:01 bogon systemd[1]: Reload failed for SYSV: nginx is a World Wide Web server. It is used to servea.
问题解决思路:
配置文件中指定nginx进程文件,nginx.pid是nginx的进程文件,文件中一般只会写一个进程的编号。所以我们先查看配置文件中的进程文件的地址。查看 安装目录下的/conf/nginx.conf 在这里我的是 /opt/stx/soft/tengine2.2.0/conf/nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#error_log "pipe:rollback logs/error_log interval=1d baknum=7 maxsize=2G";
pid logs/nginx.pid;
nginx的进程目录在logs/nginx.pid 如果这行被注释,则pid文件在 /var/run/nginx 如果没有这个目录则创建这个目录
mkdir -p /var/run/nginx
我们在重新运行nginx的时候需要去告诉运行环境去加载nginx的进程配置。所以需要指定配置文件
在我的环境中:
/opt/stx/soft/tengine2.2.0/sbin/nginx -c /opt/stx/opt/tengine2.2.0/conf/nginx.conf
执行后,再次查看会发现刚才指定的目录下有了nginx.pid文件。然后重启nginx就恢复正常了
systemctl reload nginx