问题
Centos7 配置systemctl的Nginx启动服务,start一直卡着,stop不生效
1.启动Nginx时一直卡着不动在 Starting nginx (via systemctl),实际端口是开启了,必须通过Ctrl + C强制关闭
2.关闭Nginx时,提示成功,但是端口没关闭
查找
查看Nginx 状态日志如下
[root@xxx nginx-1.17.2]# systemctl status nginx
nginx.service - SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server
Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled)
Active: inactive (dead) since Thu 2019-08-08 05:37:04 EDT; 2min 15s ago
Docs: man:systemd-sysv-generator(8)
CGroup: /system.slice/nginx.service
├─21402 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
└─21403 nginx: worker process
Aug 08 05:36:50 10-0-94-90 systemd[1]: Starting SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server...
Aug 08 05:36:50 10-0-94-90 nginx[21393]: Starting nginx: [ OK ]
Aug 08 05:36:50 10-0-94-90 systemd[1]: PID file /usr/local/nginx/logs/nginx.pid not readable (yet?) after start.
Aug 08 05:37:04 10-0-94-90 systemd[1]: Stopped SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server.
原因
/usr/local/nginx/conf/nginx.conf 中的 pid 位置 和 /etc/init.d/nginx 中 pid 位置配置不一样
修改PID文件路径即可解决上面问题
解决:修改/etc/init.d/nginx 配置的PID文件路径和nginx.conf文件中的PID路径一致