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

我发现了以前从未有过的问题。

我只需要删除/etc/nginx/sites-available/default。然后就成功了。

此删除将只删除符号链接,作为备份,您可以在默认文件中找到 /etc/nginx/sites-enabled /违约

我的conf在/etc/nginx/default


[::]: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


我通过运行:

sudo apachectl stop

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

在Ubuntu上运行:

sudo /etc/init.d/apache2 stop

我也得到了同样的错误。

nginx: [emerg] bind() to [::]:80 failed(98:地址已被使用)

当我在浏览器中输入localhost时,我得到

它的工作原理!

这是此服务器的默认web页面。

web服务器软件正在运行,但还没有添加内容。 而不是nginx的欢迎页面,apache2运行在相同的端口上,

找到apache2 ports.conf文件 sudo /etc/apache2/ports.conf 将端口更改为80以外的端口,我将其更改为70 保存文件 重新启动系统

它也适用于你,如果你在浏览器中输入localhost,你会得到nginx欢迎页面


我有几个*。保存文件(紧急转储从nano)从不同的NGINX配置文件在my sites- available目录。一旦我删除了这些.save文件,NGINX重新启动正常。我以为这些是无害的,因为没有相应的符号链接,但我想我错了。


请尝试执行该命令

sudo fuser -k 443/tcp
service nginx restart

fuser命令将找到进程id(PID), -k标志将杀死进程,使nginx重新启动。


首先修改apache监听端口80为8080 在/etc/apache2/ports.conf中包含Apache

Listen 1.2.3.4:80 to 1.2.3.4:8080
sudo service apache2 restart 

or

sudo service httpd restart    // in case of centos

然后添加nginx作为反向代理服务器,将监听apache端口

server {
 listen   1.2.3.4:80;
 server_name  some.com;

 access_log  /var/log/nginx/something-access.log;

 location / {
  proxy_pass http://localhost:8080;
  proxy_redirect off;
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 }


location ~* ^.+\.(jpg|js|jpeg|png)$ {
   root /usr/share/nginx/html/;
}

location /404.html {
  root /usr/share/nginx/html/40x.html;
}

error_page 404 /404.html;
    location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
    location = /50x.html {
}

# put code for static content like js/css/images/fonts
}

修改后重启nginx服务器

sudo service nginx restart

现在所有流量都将由nginx服务器处理,并将所有动态请求发送到apache,静态内容由nginx服务器提供。

对于像缓存这样的高级配置:

https://www.linode.com/docs/web-servers/nginx/slightly-more-advanced-configurations-for-nginx/#basic-nginx-caching


我在letsencrypt (certbot)和nginx中遇到了同样的问题,

裁判:https://github.com/certbot/certbot/issues/5486

此错误还没有解决方案

因此,a更改了一个cron为renew(在renew后重新加载)(使用certbot的建议)

-- in /etc/cron.d/certbot
from
0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(3600))' && certbot -q renew 
to
0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(3600))' && certbot -q renew --pre-hook "service nginx stop" --post-hook "service nginx start"

日志(短):

-- in /var/log/syslog
Jun 10 00:14:25 localhost systemd[1]: Starting Certbot...
Jun 10 00:14:38 localhost certbot[22222]: nginx: [error] open() "/run/nginx.pid$
Jun 10 00:14:41 localhost certbot[22222]: Hook command "nginx" returned error c$
Jun 10 00:14:41 localhost certbot[22222]: Error output from nginx:
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:443 $
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:80 f$
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:443 $
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:80 f$
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:443 $
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:80 f$
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:443 $
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:80 f$
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:443 $
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:80 f$
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] still could not bind()
Jun 10 00:14:41 localhost systemd[1]: Started Certbot.


-- in /var/log/nginx/error.log
2018/06/10 00:14:27 [notice] 22233#22233: signal process started
2018/06/10 00:14:31 [notice] 22237#22237: signal process started
2018/06/10 00:14:33 [notice] 22240#22240: signal process started
2018/06/10 00:14:34 [notice] 22245#22245: signal process started
2018/06/10 00:14:38 [notice] 22255#22255: signal process started
2018/06/10 00:14:38 [error] 22255#22255: open() "/run/nginx.pid" failed (2: No $
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:443 failed (98: Addr$
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:80 failed (98: Addre$
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:443 failed (98: Addr$
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:80 failed (98: Addre$
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:443 failed (98: Addr$
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:80 failed (98: Addre$
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:443 failed (98: Addr$
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:80 failed (98: Addre$
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:443 failed (98: Addr$
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:80 failed (98: Addre$
2018/06/10 00:14:39 [emerg] 22261#22261: still could not bind()

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

而不是

sudo systemctl restart nginx

我不得不使用:

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

我也遇到过类似的问题。日志如下所示

2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:443 failed (98: Address already in use)
2018/10/31 12:54:20 [emerg] 128005#128005: bind() to [::]:80 failed (98: Address already in use)
2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:443 failed (98: Address already in use)
2018/10/31 12:54:20 [emerg] 128005#128005: bind() to [::]:80 failed (98: Address already in use)
2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:443 failed (98: Address already in use)
2018/10/31 12:54:20 [emerg] 128005#128005: bind() to [::]:80 failed (98: Address already in use)
2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:443 failed (98: Address already in use)
2018/10/31 12:54:20 [emerg] 128005#128005: bind() to [::]:80 failed (98: Address already in use)
2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:443 failed (98: Address already in use)
2018/10/31 12:54:20 [emerg] 128005#128005: bind() to [::]:80 failed (98: Address already in use)
2018/10/31 12:54:20 [emerg] 128005#128005: still could not bind()
2018/10/31 12:54:23 [alert] 127997#127997: unlink() "/run/nginx.pid" failed (2: No such file or directory)
2018/10/31 22:40:48 [info] 36948#36948: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:68
2018/10/31 22:50:40 [emerg] 37638#37638: duplicate listen options for [::]:80 in /etc/nginx/sites-enabled/default:18
2018/10/31 22:51:33 [info] 37787#37787: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:68

最后一个[emerg]显示了[::]:80的重复监听选项,这意味着有多个nginx块文件包含[::]:80。

我的解决方案是删除[::]:80设置之一

附注:你可能有默认块文件。我的建议是将该文件作为端口80的默认服务器。并从其他块文件中删除[::]:80


继续关注@lfender6445和@SAURABH回答——

我的问题还在于,在升级到Vagrant 2.2.2之后,当客户机启动时,Apache2作为web服务器运行。在过去,我只使用nginx作为web服务器。

vagrant ssh进入机箱,并运行以下命令使Apache2在guest机箱引导时不启动:

sudo update-rc.d -f apache2 remove

退出ssh,流浪汉停下来,流浪汉起来。问题解决了。


如果在尝试上述任何解决方案后问题仍然存在,请重新启动服务器一次。这对我很有用:)


在我的例子中,Apache、Apache2或Nginx中的一个服务已经在运行,因此我无法启动另一个服务。


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

grep -r listen /etc/nginx/*

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

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

在我的例子中,罪魁祸首是一个服务器块,它包含:

        listen  127.0.0.1:80;
        listen  [::1]:80 ipv6only=on;
        server_name  localhost;

在Linux上,侦听特定IP的套接字(例如[::1]:80)与侦听同一端口但任何IP的套接字(例如[::]:80)发生冲突。通常nginx会在幕后使用一个套接字来透明地处理这个问题。然而,在listen指令上显式指定ipv6only(或某些其他选项)会迫使nginx(尝试)为它创建一个单独的套接字,从而导致Address already in use错误。

由于ipv6only=on是默认的(自1.3.4以来),修复只是简单地从这个指令中删除该选项,并确保ipv6only不在我的配置中的其他任何地方使用。


我使用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停止尝试运行另一个实例。


我也有同样的问题,但我看到Nginx监听了80端口:

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      9730/nginx 

但是当我试图重新启动它时,我有错误:

    service nginx restart
Stopping nginx:                                            [FAILED]
Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] still could not bind()

我的问题是在配置文件,我设置PID文件,似乎系统不能正确捕获它:

user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

当我取出它时,它工作了。


我在AWS光帆上有这个错误,使用上面的顶部答案

from

listen [::]:80;

to

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

然后在我的AWS帐户中点击“重启”按钮,我有主服务器Apache和Nginx作为代理。


我知道这是旧的,但也要确保没有一个docker集装箱已经在80端口。那是我的问题。


我通过跑步来解决

sudo killall apache2

sudo fuser -k 443/tcp

最后

sudo service nginx start

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

检查:

Sudo netstat -plant | grep 80

停止Apache并重启NGINX:

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


在Ubuntu上对我有效的快速解决方案。首先找到当前运行的nginx实例:

PS 辅助 |格雷普·恩金克斯

复制pid(例如123456)并运行

杀死-9 123456


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

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


我用nginx运行Varnish服务器。我的varnish服务器运行在端口80上,因此,我的nginx服务器没有启动。我在所有nginx配置文件中将端口更改为8088,但我的default.conf文件在/etc/nginx/conf中。d目录下的Ubuntu服务器。

由于我的conf.d目录包含在主/etc/nginx.conf文件中,nginx没有启动。

将“/etc/nginx/conf.d/default.conf”重命名为“/etc/nginx/conf.d/default.conf”。/etc/nginx/conf.d/*.conf;从我的nginx.conf文件。


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

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

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


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

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


另一个可能的问题是,当你在nginx中通过根目录启动ngix时,它会启动两次。例如,Config是对用户'www-data'进行配置的。 因此,您需要切换到另一个用户(而不是根用户)来启动服务。