不能重启Nginx, Nginx重启报错, Can not restart Nginx, Job for nginx.service failed because the control process exited with error code., nginx.service failed because the control process exited

不能重启Nginx, Nginx重启报错, Can not restart Nginx, Job for nginx.service failed because the control process exited with error code., nginx.service failed because the control process exited
不能重启Nginx, Nginx重启报错, Can not restart Nginx, Job for nginx.service failed because the control process exited with error code., nginx.service failed because the control process exited

 

问题:

 

我试图重新启动 nginx:

$ sudo service nginx restart
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:

$ systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Thu 2019-04-25 12:31:46 UTC; 55s ago
     Docs: man:nginx(8)
  Process: 8232 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
  Process: 8221 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)

 

journalctl -xe

$ sudo journalctl -u nginx
    - Logs begin at Thu 2019-03-21 01:07:26 UTC, end at Thu 2019-04-25 12:54:26 UTC. --
Apr 25 10:33:29 ubuntu-s-michaelsimsoe systemd[1]: Stopping A high performance web server and a reverse proxy server...
Apr 25 10:33:29 ubuntu-s-michaelsimsoe systemd[1]: Stopped A high performance web server and a reverse proxy server.

 

 

解决方案:

 

其他一些进程已经在运行并绑定到端口 80/443,因此 systemd 无法启动 nginx。这几乎总是因为该进程是手动启动的,而不是通过 systemd 启动的,或者因为您试图同时启动两个不同的 Web 服务器。

要解决此问题,请在通过 systemd 重新启动之前自行终止该进程。

sudo killall apache2

 

当然,还有其他更好的方式就是:

尝试运行以下两个命令:

sudo fuser -k 80/tcp

sudo fuser -k 443/tcp

 

然后执行

sudo service nginx restart

 

如果这有效,则您的托管服务提供商可能会在全新安装期间默认在您的服务器上安装 Apache,因此请继续阅读以获得更永久的修复。

如果这不起作用,请继续阅读以确定问题所在。

执行:

sudo netstat -tulpn

执行上述操作后,您将得到类似以下内容:

Proto Recv-Q Send-Q Local Address           Foreign Address         State    PID/Program name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1762/httpd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1224/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1528/sendmail:acce
tcp6       0      0 :::22                   :::*                    LISTEN      1224/sshd

 

您可以看到端口 80 被 httpd (Apache) 阻止了。如果您使用 SSL,这也可能是端口 443。

获取使用端口 80 或 443 的进程的 PID。并发送更改<PID>值的 kill 命令:

sudo kill -2 <PID>

请注意,在我的示例中,Apache 的 PID 值是1762这样我会执行sudo kill -2 1762

 

除此后,您可以执行以下操作:

sudo fuser -k 80/tcp

sudo fuser -k 443/tcp

 

现在 80 或 443 端口已清除,您可以通过运行以下命令来启动 Nginx:

sudo service nginx restart

还建议删除之前阻塞端口 80 和 443 的任何内容。这将避免将来发生任何冲突。

 

 

本文:不能重启Nginx, Nginx重启报错, Can not restart Nginx, Job for nginx.service failed because the control process exited with error code., nginx.service failed because the control process exited

Loading

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.