1.背景及描述
當(dāng)我使用systemctl start nginx.service或者service nginx start命令啟動nginx,發(fā)現(xiàn)啟動失敗.當(dāng)使用nginx -t卻顯示OK.查看狀態(tài),信息如下:
情況1:
[root@CentOS-7-x86_64-DVD-2207-bt /]# nginx -t
nginx: the configuration file /www/server/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /www/server/nginx/conf/nginx.conf test is successful
[root@CentOS-7-x86_64-DVD-2207-bt /]# systemctl status nginx.service
● nginx.service - (null)
Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since 日 2023-03-05 13:22:07 CST; 58min ago
Docs: man:systemd-sysv-generator(8)
3月 05 13:22:07 CentOS-7-x86_64-DVD-2207-bt systemd[1]: Starting (null)...
3月 05 13:22:07 CentOS-7-x86_64-DVD-2207-bt systemd[1]: nginx.service: control process exited, code=exited status=203
3月 05 13:22:07 CentOS-7-x86_64-DVD-2207-bt systemd[1]: Failed to start (null).
3月 05 13:22:07 CentOS-7-x86_64-DVD-2207-bt systemd[1]: Unit nginx.service entered failed state.
3月 05 13:22:07 CentOS-7-x86_64-DVD-2207-bt systemd[1]: nginx.service failed.
情況2:
[root@localhost logs]# systemctl status nginx.service
● 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: failed (Result: exit-code) since 五 2020-10-16 10:52:10 CST; 11s ago
Docs: man:systemd-sysv-generator(8)
Process: 38258 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=203/EXEC)
10月 16 10:52:10 localhost.localdomain systemd[1]: Starting SYSV: NGINX is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server...
10月 16 10:52:10 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=203
10月 16 10:52:10 localhost.localdomain systemd[1]: Failed to start SYSV: NGINX is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server.
10月 16 10:52:10 localhost.localdomain systemd[1]: Unit nginx.service entered failed state.
10月 16 10:52:10 localhost.localdomain systemd[1]: nginx.service failed.
123456789101112
2.臨時解決方案
2.1 使用./nginx啟動
參考多篇博客均以失敗告終,最后偶然發(fā)現(xiàn),如果通過安裝目錄下sbin中的nginx可以正常啟動.命令如下:
#進入nginx安裝目錄下的sbin目錄,并指定配置文件啟動
./nginx -c /etc/local/nginx/conf/nginx.conf
12
2.2 殺掉./nginx啟動的進程,再使用service方式啟動
也有博客是這樣說的
只是很多時候我們都先用/usr/local/nginx/sbin/nginx來啟動了nginx
只要找到這個進程kill掉以后,再執(zhí)行/etc/rc.d/init.d/nginx start就一切正常了
123
即:先kill掉./nginx啟動的進程,然后再換成service nginx start方式啟動
3.總結(jié)
如果符合如下狀態(tài)
nginx -t顯示狀態(tài)ok
systemctl start nginx.service或者service nginx start命令啟動nginx失敗
報錯信息為:nginx.service - SYSV: NGINX is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server
報錯信息為:Process: 38258 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=203/EXEC)
請嘗試:
更改為./nginx -c /etc/local/nginx/conf/nginx.conf方式啟動文章來源:http://www.zghlxwxcb.cn/news/detail-456114.html
kill掉./nginx啟動的進程,然后再換成service nginx start方式啟動文章來源地址http://www.zghlxwxcb.cn/news/detail-456114.html
到了這里,關(guān)于nginx無法啟動的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!