重启NGINX失败

时间:2017-01-02 16:10:16

标签: ubuntu nginx

我在Ubuntu 16.04上安装了NGINX并编辑了我的配置。 当我想用sudo service nginx restart重新启动时,我收到错误:

  

nginx.service的作业失败,因为控制进程已退出   错误代码。请参阅“systemctl status nginx.service”和“journalctl -xe”   详情。

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 Mon 2017-01-02 16:07:54 UTC; 15s ago
  Process: 26515 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
  Process: 26510 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 3464 (code=exited, status=0/SUCCESS)

Jan 02 16:07:53 IF-STG-001 nginx[26515]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jan 02 16:07:53 IF-STG-001 nginx[26515]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 
Jan 02 16:07:53 IF-STG-001 nginx[26515]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jan 02 16:07:54 IF-STG-001 nginx[26515]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 16:07:54 IF-STG-001 nginx[26515]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jan 02 16:07:54 IF-STG-001 nginx[26515]: nginx: [emerg] still could not bind()
Jan 02 16:07:54 IF-STG-001 systemd[1]: nginx.service: Control process exited, code=exited status=1
Jan 02 16:07:54 IF-STG-001 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Jan 02 16:07:54 IF-STG-001 systemd[1]: nginx.service: Unit entered failed state.
Jan 02 16:07:54 IF-STG-001 systemd[1]: nginx.service: Failed with result 'exit-code'.

为什么我不能重启我的nginx实例?我不明白为什么阻止重启

2 个答案:

答案 0 :(得分:2)

错误消息的重要部分是

  

bind()到0.0.0.0:80失败(98:地址已在使用中)

因此,在启动时,nginx无法绑定到端口80,因为某些其他程序已绑定到此端口。当其他程序从此套接字退出或解除绑定时,您将只能启动nginx。

要查找当前绑定此端口的程序,可以以root身份运行此命令(例如使用sudo):

ss -ntlp "sport = :80"

答案 1 :(得分:0)

当您在同一台计算机上运行apache服务器时,通常会出现此问题,而nginx需要使用同一端口来运行,即80。 尝试将Nginx端口更改为8080或其他。 即 {收听8080 default_server;收听[::]:8080 default_server;} 然后重启nginx