突然我得到下面的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

当前回答

我使用supervisor在Docker容器上并排运行Nginx和Gunicorn。

这是用于supervisor的配置:

[supervisord]
nodaemon=true

[program:gunicorn]
command = /project/start.sh
user = www-data

[program:nginx]
command=/usr/sbin/nginx

问题是我如何在默认情况下启动Ngnix,它在前台运行。这使得管理器重试运行另一个Nginx实例。

你可以通过在命令行中添加-g 'daemon off;'或daemon off;在配置文件的顶部,Nginx停留在前台,supervisor停止尝试运行另一个实例。

其他回答

用编辑器打开/etc/nginx/nginx.conf,注释掉这行-

include /etc/nginx/sites-enabled/*;

重新启动nginx,你就可以开始了!

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

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

我通过运行:

sudo apachectl stop

结果apache在后台运行,阻止nginx在指定的端口上启动。

在Ubuntu上运行:

sudo /etc/init.d/apache2 stop

我使用supervisor在Docker容器上并排运行Nginx和Gunicorn。

这是用于supervisor的配置:

[supervisord]
nodaemon=true

[program:gunicorn]
command = /project/start.sh
user = www-data

[program:nginx]
command=/usr/sbin/nginx

问题是我如何在默认情况下启动Ngnix,它在前台运行。这使得管理器重试运行另一个Nginx实例。

你可以通过在命令行中添加-g 'daemon off;'或daemon off;在配置文件的顶部,Nginx停留在前台,supervisor停止尝试运行另一个实例。

[::]:80是ipv6地址。

如果你有一个nginx配置,监听端口80和端口[::]:80,就会导致这个错误。

我有以下在我的默认网站可用文件:

listen 80;
listen [::]:80 default_server;

你可以通过添加ipv6only=on到[::]:80来解决这个问题,就像这样:

listen 80;
listen [::]:80 ipv6only=on default_server;

有关更多信息,请参见:

http://forum.linode.com/viewtopic.php?t=8580

http://wiki.nginx.org/HttpCoreModule#listen