問題描述:
(flaskApi) [root@67 flaskDemo]# service nginx start Redirecting to /bin/systemctl start nginx.service Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
確認問題:
當不能使用service nginx start 開啟或者使用service nginx stop 關閉時,查看systemctl status nginx 會有一定的錯誤提示
systemctl status nginx -l
-l表示:可以展示全部錯誤信息,否則可能錯誤信息會被折疊
Hint: Some lines were ellipsized, use -l to show in full.
返回的錯誤提示:
從這里我們可以看出,是80端口被占用了
9月 17 14:54:21 67.59.247.60.static.bjtelecom.net nginx[25531]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
通過命令查看80端口被哪個進程占用了
netstat -tpnul
可以看到是httpd,這個進程需要是24小時啟動了,不能關掉
所以接下來的解決辦法有2種
-
- 修改nginx的配置文件nginx.conf指定nginx啟動時使用別的端口號,例如81
- 或者殺掉占用80端口的進程,參照:centOS7殺死進程命令
查看nginx的安裝目錄,並找到nginx.conf的目錄:
rpm -ql grep nginx
或者直接使用find命令查找 nginx.conf
(flaskApi) [root@67 flaskDemo]# find / -name nginx.conf
/etc/nginx/nginx.conf
使用nano命令編輯nginx.conf配置文件,圖示中2處默認為80的端口號改為81
nano /etc/nginx/nginx.conf
另外應當注意:
service nginx start 是centos6.x的命令 , centos7.x使用 systemctl start nginx
再次啟動nginx,沒看到啟動成功的提示信息
(flaskApi) [root@67 flaskDemo]# /bin/systemctl start nginx.service
打印一下當前的進程,可以看到nginx已經啟動了,並且使用的是81端口
參照文檔:
nginx 在Centos 7 版本的yum安裝 和目錄解釋
nginx啟動報錯的處理辦法,參照:
https://blog.csdn.net/qq_40907977/article/details/91989353