突然我得到下面的nginx错误

 * Restarting nginx
 * Stopping nginx nginx
   ...done.
 * Starting nginx nginx
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
   ...done.
   ...done.

如果我跑

lsof -i :80 or sudo fuser -k 80/tcp 

我什么也得不到。80端口上没有东西

然后我运行如下:

sudo netstat -pan | grep ":80"
tcp        0      0 127.0.0.1:8070          0.0.0.0:*               LISTEN      15056/uwsgi     
tcp        0      0 10.170.35.97:39567      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39564      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39584      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39566      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39571      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39580      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39562      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39582      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39586      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39575      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39579      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39560      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39587      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39591      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39589      10.158.58.13:8080       TIME_WAIT   - 

我被难住了。我如何调试这个?

我在端口8070上使用带有代理通道的uwsgi。Uwsgi正在运行。Nginx则不然。我使用的是ubuntu 12.4

下面是我的nginx conf文件的相关部分

upstream uwsgi_frontend {
          server 127.0.0.1:8070;
        }
server {
listen 80;
        server_name 127.0.0.1;
        location = /favicon.ico {
                  log_not_found off;
                }



                location / {
                       include uwsgi_params;
                       uwsgi_buffering off;

                       uwsgi_pass 127.0.0.1:8070;
                 }
        }

下面是我在ubuntu 12.04上安装nginx的方法

nginx=stable;add-apt-repository ppa:nginx/$nginx;
apt-get update
apt get install nginx-full

当前回答

问题——我有这个问题。基本上,我所做的就是用正常的nginx命令启动nginx,然后尝试用service nginx reload / restart重新启动nginx,然后我得到这个错误

解决方案-使用nginx -s stop停止nginx,然后重新启动nginx服务器使用服务nginx重启问题解决。

其他回答

我的情况不同,我必须杀死正在运行的Nginx进程来重新启动它。

而不是

sudo systemctl restart nginx

我不得不使用:

sudo pkill -f nginx & wait $!
sudo systemctl start nginx

对我来说,问题是我在用Supervisor和Systemd运行一个应用程序。在应用程序与Supervisor运行时,我有一个配置文件来处理Nginx。我停止了这个过程,重新启动了监督者。

现在Nginx由Systemd推出,我不再有这个问题了。

我的问题是我有重叠的监听指令。我设法通过运行来找出重叠的指令

grep -r listen /etc/nginx/*

两个文件在同一个端口监听:

/etc/nginx/conf.d/default.conf:           listen 80;  
/etc/nginx/sites-enabled/default.conf:    listen 80;

多个服务可以在同一个端口上侦听。 这个问题通常来自于在同一台机器上混合使用Apache和NGINX。

检查:

Sudo netstat -plant | grep 80

停止Apache并重启NGINX:

Sudo systemctl stop apache2 && Sudo systemctl restart nginx && Sudo systemctl status nginx

我通过跑步来解决

sudo killall apache2

sudo fuser -k 443/tcp

最后

sudo service nginx start