启动失败,查看状态(systemctl status nginx.service)如下:
查看状态
[root@iZbpZ init.d]# systemctl status nginx.service
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset>
Active: failed (Result: exit-code) since Mon 2022-01-17 21:53:51 CST; 19s ago
Process: 1729 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=203/EXEC)
Process: 1728 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=>
Jan 17 21:53:51 iZbp18qk0bio1jludfhze4Z systemd[1]: Starting The nginx HTTP and >
Jan 17 21:53:51 iZbp18qk0bio1jludfhze4Z systemd[1]: nginx.service: Control proce>
Jan 17 21:53:51 iZbp18qk0bio1jludfhze4Z systemd[1]: nginx.service: Failed with r>
Jan 17 21:53:51 iZbp18qk0bio1jludfhze4Z systemd[1]: Failed to start The nginx HT>
lines 1-10/10 (END)...skipping...
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Mon 2022-01-17 21:53:51 CST; 19s ago
Process: 1729 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=203/EXEC)
Process: 1728 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Jan 17 21:53:51 iZbp18qk0bio1jludfhze4Z systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jan 17 21:53:51 iZbp18qk0bio1jludfhze4Z systemd[1]: nginx.service: Control process exited, code=exited status=203
Jan 17 21:53:51 iZbp18qk0bio1jludfhze4Z systemd[1]: nginx.service: Failed with result 'exit-code'.
Jan 17 21:53:51 iZbp18qk0bio1jludfhze4Z systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
看出来了,/usr/lib/systemd/system/nginx.service 配置不对:
贴下/usr/lib/systemd/system/nginx.service 的正确配置:
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/server/nginx/logs/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
# ExecStartPre=/usr/bin/rm -f /server/nginx/logs/nginx.pid
ExecStartPre=/server/nginx/sbin/nginx -t
ExecStart=/server/nginx/sbin/nginx -c /server/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=mixed
PrivateTmp=true
[Install]
WantedBy=multi-user.target
相关的命令:
打开目录查看相关的配置:
vim /usr/lib/systemd/system/nginx.service
修改了配置后让该文件生效
systemctl enable nginx.service
相关的命令
systemctl start nginx.service 启动nginx
systemctl stop nginx.service 结束nginx
systemctl restart nginx.service 重启nginx
上面的启动失败的的话查看一下原因:
systemctl status nginx.service
主要看nginx.service 是否正确
能正常启动的话说明OK了。可以点击重启试试