Ubuntu 重新启动NGINX失败

Ubuntu 重新启动NGINX失败,ubuntu,nginx,Ubuntu,Nginx,我在Ubuntu 16.04上安装了NGINX并编辑了我的配置。 当我想用sudo服务nginx restart重新启动时,我得到错误: nginx.service的作业失败,因为控制进程已退出 错误代码。请参阅“systemctl状态nginx.service”和“journalctl-xe” 详情请参阅 nginx.service status的内容为: nginx.service - A high performance web server and a reverse proxy ser

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

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

nginx.service status的内容为:

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实例?我不明白为什么它会阻止重启

错误消息的重要部分是

将()绑定到0.0.0.0:80失败(98:地址已在使用)

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

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


当您在与apache相同的机器上运行apache server时,通常会出现此问题,nginx需要相同的端口才能运行,即80。 尝试将nginx端口更改为8080或其他。 即 {listen 8080 default_server;listen[::]:8080 default_server;}
并在执行此操作时重新启动nginx

,我得到:
State Recv-Q Send-Q本地地址:端口对等地址:端口侦听0 128*:80*:*侦听0 128::80:*
确保以root用户身份运行程序。普通用户没有权限检查哪个程序绑定到端口。啊,好的,因此,输出现在是状态Recv-Q Send-Q本地地址:端口对等地址:端口侦听0 128*:80*:*用户:((((“nginx”,pid=26359,fd=6),(“nginx,pid=26358,fd=6))侦听0 128:::80:::*用户:((“nginx”,pid=26359,fd=7),(“nginx,pid=26358,fd=7))
似乎正在运行另一个绑定到端口的nginx进程。它可能会也可能不会受到系统的监督。您可以尝试使用
kill 26359
终止程序。如果您打算实际运行一个生产Web服务器,那么您可能应该尝试阅读一些关于基本系统管理任务的内容,如下面所述!实际上,我刚刚开始做这个,所以这更像是我的学习环境
ss -ntlp "sport = :80"