【问题标题】:nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
【发布时间】:2020-01-15 01:46:42
【问题描述】:

我无法启动 nginx。每次我在命令行中输入“nginx”时,我都会看到:

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)

打印了几次

我使用的是 ubuntu 14.04

我已经累了:

  1. 将本地地址更改为80以外的其他东西,例如70,但是错误是

    nginx: [emerg] bind() to 0.0.0.0:70 failed (98: Address already in use)

    nginx: [emerg] bind() to [::]:70 failed (98: Address already in use)

;

  1. 定影器-k 80/tcp:

我的 netstat -tulpn 显示如下:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      18170/nginx 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      3156/sshd   
tcp6       0      0 :::80                   :::*                    LISTEN      18170/nginx 
tcp6       0      0 :::22                   :::*                    LISTEN      3156/sshd   

之后 定影器 -k 80/tcp 我得到: 80/tcp: 18170 18171 netstat 显示:

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      3156/sshd   
tcp6       0      0 :::22                   :::*                    LISTEN      3156/sshd   

我尝试重启 nginx

 service nginx stop
    service nginx start

但是当我再次输入 nginx 时,我看到了

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)

再一次,几次。

nginx -t 

显示:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

另外,我没有安装 apache。

我的 /etc/nginx/conf.d/[站点名称]conf:

server {

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

        server_name     [sitename] www.[sitename];
        root            /var/www/[sitename];
        index           index.html;

        gzip            on;
        gzip_comp_level 3;
        gzip_types      text/plain text/css application/javascript image/*;
}

我试着跑了:

grep -r listen /etc/nginx/*

检查listen是否没有设置两次,但只显示:

/etc/nginx/conf.d/[sitename].conf:      listen          80;
/etc/nginx/conf.d/[sitename].conf:      listen          [::]:80 ipv6only=on;
/etc/nginx/nginx.conf:#         listen     localhost:110;
/etc/nginx/nginx.conf:#         listen     localhost:143;

我很困惑,因为 netstat 显示 nginx 实际上在那个端口上,但我仍然收到错误消息并且我的网页无法访问(404 未找到,nginx)

我还能尝试什么?

【问题讨论】:

  • 为什么要手动运行nginx?它作为服务运行。
  • 我正在通过 linode ssh 进行操作,并且由于他们的指示,我已经完成了所有操作 - 我不知道如何以任何其他方式进行操作;尤其是我的网站没有运行。

标签: nginx


【解决方案1】:

我在 Ubuntu 16.04LTS 上的 Nginx 1.16.1 上有类似的症状。我很确定已经预加载了像 /etc/nginx/sites-available/* 这样的配置来导致这个冲突。

我只是重新安装

apt purge   nginx nginx-common nginx-full
apt install nginx nginx-common nginx-full

systemctl restart nginx

然后修复就消失了

【讨论】:

    【解决方案2】:

    我认为正在发生的事情是您已经运行了 nginx,并且您正在尝试再次运行它。您有两种启动方式。

    1- 手动使用sudo nginx

    2- 或者使用 Systemctl(在重启或失败的情况下自动启动 nginx)

    因此,如果您已经使用了“1”,那么运行“2”通常会告诉您地址已被占用。反之亦然。

    我建议你重新启动,然后使用 systemctl sudo systemctl restart nginx 重新启动 nginx,然后检查它是否正在运行 sudo systemctl status nginx。如果它处于活动状态,则不要尝试再次运行sudo nginx

    【讨论】:

      猜你喜欢
      • 2013-02-05
      • 1970-01-01
      • 2013-08-03
      • 2014-10-13
      • 2013-04-05
      • 1970-01-01
      • 2020-11-25
      • 1970-01-01
      • 2013-08-31
      相关资源
      最近更新 更多