[root@localhost ~]# systemctl restart nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.查看详细信息如下
[root@localhost ~]# systemctl status nginx ● nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since 三 2020-10-21 11:09:28 CST; 14s ago Process: 4480 ExecStart=/usr/sbin/nginx (code=exited, status=1/FAILURE) Process: 4477 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS) Process: 4475 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS) 10月 21 11:09:27 localhost.localdomain nginx[4480]: nginx: [emerg] bind() to [::]:80 failed (98...e) 10月 21 11:09:27 localhost.localdomain nginx[4480]: nginx: [emerg] bind() to 0.0.0.0:80 failed ...e) 10月 21 11:09:27 localhost.localdomain nginx[4480]: nginx: [emerg] bind() to [::]:80 failed (98...e) 10月 21 11:09:28 localhost.localdomain nginx[4480]: nginx: [emerg] bind() to 0.0.0.0:80 failed ...e) 10月 21 11:09:28 localhost.localdomain nginx[4480]: nginx: [emerg] bind() to [::]:80 failed (98...e) 10月 21 11:09:28 localhost.localdomain systemd[1]: nginx.service: control process exited, code=...=1 10月 21 11:09:28 localhost.localdomain nginx[4480]: nginx: [emerg] still could not bind() 10月 21 11:09:28 localhost.localdomain systemd[1]: Failed to start The nginx HTTP and reverse p...r. 10月 21 11:09:28 localhost.localdomain systemd[1]: Unit nginx.service entered failed state. 10月 21 11:09:28 localhost.localdomain systemd[1]: nginx.service failed. Hint: Some lines were ellipsized, use -l to show in full.进程还是存在不过对应的进程id+1了,也就是之前的nginx不存在但是又启动了一次所以进程id+1了
此时的nginx服务,使用了nginx命令启动,而并非传统的systemctl工具执行,所以此时如果要停止nginx服务要使用nginx -s stop命令去执行,而不是systemctl stop nginx命令
[root@localhost ~]# nginx -s stop nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)这里使用nginx -s stop又发生一次报错,说/run/nginx.pid不存在,因为我们之前kill进程的时候改变了参数导致进程不知道指定的配置文件是谁?解决方法:nginx -c /etc/nginx/nginx.conf,再次指定配置文件
[root@localhost ~]# nginx -s stop //这个时候在停止服务就不会报错了如果启动nginx服务是使用命令行模式启动的,用systemctl工具是关闭不了的,但是使用systemctl工具启动的,nginx命令行是可以关闭的,也就是nginx命令行的优先级高于systemctl工具的优先级,为了以后的方便管理建议使用nginx命令行模式来管理nginx服务。