Nginx 无法启动并出现错误:bind() to 0.0.0.0:80 failed

Nginx 无法启动并出现错误:bind() to 0.0.0.0:80 failed

最近,我创建了一个 Digital Ocean 实例,并使用基本的 LEMP 堆栈对其进行了设置。我还使用以下 nginx 配置将其连接到域:

server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/example.com;

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

几天后,我决定将东西转移到新服务器上,因此我创建了该容器的快照,并使用完全相同的快照/图像启动了新服务器。

但结果并不相同。当我尝试重新加载 Nginx 时,我得到了以下信息:

@:~$ sudo systemctl reload nginx
nginx.service is not active, cannot reload.

由于某种原因,Nginx 尚未启动并且退出并出现错误(日志来自/var/log/nginx/error.log):

2020/06/01 16:49:24 [emerg] 1325#1325: bind() to 0.0.0.0:80 failed (98: Address already in use)
2020/06/01 16:49:24 [emerg] 1325#1325: bind() to [::]:80 failed (98: Address already in use)
2020/06/01 16:49:24 [emerg] 1325#1325: bind() to 0.0.0.0:80 failed (98: Address already in use)
2020/06/01 16:49:24 [emerg] 1325#1325: bind() to [::]:80 failed (98: Address already in use)
2020/06/01 16:49:24 [emerg] 1325#1325: bind() to 0.0.0.0:80 failed (98: Address already in use)
2020/06/01 16:49:24 [emerg] 1325#1325: bind() to [::]:80 failed (98: Address already in use)
2020/06/01 16:49:24 [emerg] 1325#1325: bind() to 0.0.0.0:80 failed (98: Address already in use)
2020/06/01 16:49:24 [emerg] 1325#1325: bind() to [::]:80 failed (98: Address already in use)
2020/06/01 16:49:24 [emerg] 1325#1325: bind() to 0.0.0.0:80 failed (98: Address already in use)
2020/06/01 16:49:24 [emerg] 1325#1325: bind() to [::]:80 failed (98: Address already in use)
2020/06/01 16:49:24 [emerg] 1325#1325: still could not bind()

我尝试过添加ipv6only=on配置,但没有帮助。我也尝试过重新安装 Nginx,但也没有帮助。

这里可能存在什么问题?如果您缺少任何日志文件,请告诉我,我会更新帖子。

答案1

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

是否意味着某个应用程序已经使用了该端口?使用以下命令检查:

ss -ntlp

你会看到类似这样的内容:

State      Recv-Q       Send-Q              Local Address:Port             Peer Address:Port
LISTEN     0            128                       0.0.0.0:5355                  0.0.0.0:*          users:(("systemd-resolve",pid=1089,fd=13))
LISTEN     0            128                       0.0.0.0:22                    0.0.0.0:*          users:(("sshd",pid=1039,fd=4))

找到应用程序并将其关闭,apache 正在运行?

相关内容