1. 程式人生 > >解決nginx無法啟動的問題——埠被佔用

解決nginx無法啟動的問題——埠被佔用

一段時間沒使用nginx後,發現無法啟動

問題:

輸入nginx -tc /etc/nginx/nginx.conf 顯示正常
但是輸入 systemctl reload nginx 提示

Job for nginx.service invalid.

查錯:

輸入 systemctl status nginx.service -l
提示

● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Mon 2018-10-01 20:04:22 CST; 38s ago
     Docs: http://nginx.org/en/docs/
  Process: 27162 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)

Oct 01 20:04:19 VM_205_38_centos nginx[27162]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Oct 01 20:04:20 VM_205_38_centos nginx[27162]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Oct 01 20:04:20 VM_205_38_centos nginx[27162]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Oct 01 20:04:21 VM_205_38_centos nginx[27162]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Oct 01 20:04:21 VM_205_38_centos nginx[27162]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Oct 01 20:04:22 VM_205_38_centos nginx[27162]: nginx: [emerg] still could not bind()
Oct 01 20:04:22 VM_205_38_centos systemd[1]: nginx.service: control process exited, code=exited status=1
Oct 01 20:04:22 VM_205_38_centos systemd[1]: Failed to start nginx - high performance web server.
Oct 01 20:04:22 VM_205_38_centos systemd[1]: Unit nginx.service entered failed state.
Oct 01 20:04:22 VM_205_38_centos systemd[1]: nginx.service failed.

解決

vim /etc/nginx/conf.d/default.conf 

更改listen的埠,因為原來的埠被佔用( Address already in use)