问题描述:

启动nginx报错

Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

使用systemctl status nginx.service查看:

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 Sun 2019-09-01 14:42:00 CST; 27s ago
  Process: 26735 ExecStart=/usr/sbin/nginx (code=exited, status=1/FAILURE)
  Process: 26731 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 26729 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)

Sep 01 14:41:57 localhost.localdomain nginx[26735]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address alrea...use)
Sep 01 14:41:58 localhost.localdomain nginx[26735]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address alrea...use)
Sep 01 14:41:58 localhost.localdomain nginx[26735]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address alrea...use)
Sep 01 14:41:59 localhost.localdomain nginx[26735]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address alrea...use)
Sep 01 14:41:59 localhost.localdomain nginx[26735]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address alrea...use)
Sep 01 14:42:00 localhost.localdomain nginx[26735]: nginx: [emerg] still could not bind()
Sep 01 14:42:00 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1
Sep 01 14:42:00 localhost.localdomain systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Sep 01 14:42:00 localhost.localdomain systemd[1]: Unit nginx.service entered failed state.
Sep 01 14:42:00 localhost.localdomain systemd[1]: nginx.se

首先我们要弄清楚错误的原因是什么?百度了下原因,此错误是80端口被程序占用了。那么解决方法就简单了,强制关闭端口的占用就可以了,一个简单的命令就解决了。

sudo fuser -k 80/tcp #关闭占用80端口的程序

重启nginx服务就可以