Nginx:Nginx.service的作业失败,因为控制进程已退出 [英] Nginx: Job for nginx.service failed because the control process exited

查看:862
本文介绍了Nginx:Nginx.service的作业失败,因为控制进程已退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,已经尝试了几天,但我不知道该怎么办,一直在寻找答案,但是所有发现的问题都没有帮助我.

I got a problem which I have been trying to fix for a few days now and I don't know what to do, have been looking for answers but all of those I found didn't help me.

我在这里有点陌生,我真的希望有人能帮助我. 您可以告诉我我需要提供哪些信息,以期找到解决方案.

I am kinda new here and I really hope that someone can help me. You can tell me which informations I need to give in hope for finding a solution.

$ systemctl status nginx.service
nginx.service - Startup script for nginx service
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2016-03-08 13:23:35 GMT; 2min 20s ago

Mar 08 13:23:33 startdedicated.com nginx[8315]: nginx: [emerg] bind() to ------------ f...e)
Mar 08 13:23:33 startdedicated.com nginx[8315]: nginx: [emerg] bind() to ----- f...e)
Mar 08 13:23:34 startdedicated.com nginx[8315]: nginx: [emerg] bind() to ----- f...e)
Mar 08 13:23:34 startdedicated.com nginx[8315]: nginx: [emerg] bind() to ----- f...e)
Mar 08 13:23:35 startdedicated.com nginx[8315]: nginx: [emerg] bind() to ----- f...e)
Mar 08 13:23:35 .startdedicated.com nginx[8315]: nginx: [emerg] still could not bind()
Mar 08 13:23:35 startdedicated.com systemd[1]: nginx.service: control process exited, code=...=1
Mar 08 13:23:35 startdedicated.com systemd[1]: Failed to start Startup script for nginx service.
Mar 08 13:23:35 startdedicated.com systemd[1]: Unit nginx.service entered failed state.
Mar 08 13:23:35 startdedicated.com systemd[1]: nginx.service failed.

推荐答案

尝试运行以下两个命令:

Try to run the following two commands:

sudo fuser -k 80/tcp

sudo fuser -k 443/tcp

然后执行

sudo service nginx restart

如果可行,您的托管服务提供商可能会在全新安装过程中默认在您的服务器上安装Apache,因此请继续阅读以获取更多永久性补丁. 如果这不起作用,请继续阅读以找出问题所在.

If that worked, your hosting provider might be installing Apache on your server by default during a fresh install, so keep reading for a more permenant fix. If that didn't work, keep reading to identify the issue.

运行nginx -t,如果它不返回任何内容,我将验证Nginx错误日志.默认情况下,它应该位于/var/log/nginx/error.log中.

Run nginx -t and if it doesn't return anything, I would verify Nginx error log. By default, it should be located in /var/log/nginx/error.log.

您可以使用任何文本编辑器将其打开: sudo nano /var/log/nginx/error.log

You can open it with any text editor: sudo nano /var/log/nginx/error.log

在那可以找到可疑的东西吗?

Can you find something suspicious there?

您可以查看的第二个日志如下

The second log you can check is the following

sudo nano /var/log/syslog

出现此问题时,是因为托管服务提供商在全新安装过程中自动安装了Apache.它阻塞了端口80.

When I had this issue, it was because my hosting provider was automatically installing Apache during a clean install. It was blocking port 80.

当我执行sudo nano /var/log/nginx/error.log时,我得到以下内容作为错误日志:

When I executed sudo nano /var/log/nginx/error.log I got the following as the error log:

2018/08/04 06:17:33 [emerg] 634#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/08/04 06:17:33 [emerg] 634#0: bind() to [::]:80 failed (98: Address already in use)
2018/08/04 06:17:33 [emerg] 634#0: bind() to 0.0.0.0:80 failed (98: Address already in use)

以上错误告诉我们,因为它已在使用中,所以无法将nginx绑定到端口80.

What the above error is telling is that it was not able to bind nginx to port 80 because it was already in use.

要解决此问题,您需要运行以下命令:

To fix this, you need to run the following:

yum install net-tools

sudo netstat -tulpn

执行上述操作时,您将获得类似以下的内容:

When you execute the above you will get something like the following:

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.

You can see that port 80 is blocked by httpd (Apache). This could also be port 443 if you are using SSL.

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

Get the PID of the process that uses port 80 or 443. And send the kill command changing the <PID> value:

sudo kill -2 <PID>

请注意,在我的示例中,Apache的PID值为1762,因此我将执行sudo kill -2 1762

Note in my example the PID value of Apache was 1762 so I would execute sudo kill -2 1762

或者,您可以执行以下操作:

Aternatively you can execute the following:

sudo fuser -k 80/tcp

sudo fuser -k 443/tcp

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

Now that port 80 or 443 is clear, you can start Nginx by running the following:

sudo service nginx restart

还建议删除以前阻塞端口80和端口90的所有内容. 443.这样可以避免将来发生任何冲突.由于Apache(httpd)阻止了我的端口,因此我通过运行以下命令将其删除:

It is also advisable to remove whatever was previously blocking port 80 & 443. This will avoid any conflict in the future. Since Apache (httpd) was blocking my ports I removed it by running the following:

yum remove httpd httpd-devel httpd-manual httpd-tools mod_auth_kerb mod_auth_mysql mod_auth_pgsql mod_authz_ldap mod_dav_svn mod_dnssd mod_nss mod_perl mod_revocator mod_ssl mod_wsgi

希望这会有所帮助.

这篇关于Nginx:Nginx.service的作业失败,因为控制进程已退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆