0

Recently, I created a Digital Ocean instance and set it up with a basic LEMP stack. I also connected it to a domain with this nginx configuration:

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;
    }
}

A few days later I decided to move things over to a new server so I created a snapshot of this container and fired up a new server with the exact same snapshot/image.

The results were not the same though. When I try to reload Nginx I get this:

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

For some reason, Nginx hasn't started and it exits with an error (log from /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()

I have tried adding ipv6only=on to the config but it did not help. I have also tried to re-install Nginx, but it did not help either.

What could be the issue here? If you're missing any log files, just let me know and I'll update the post.

1 Answers1

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

means that some application allready used this port? check using:

ss -ntlp

you will see comething like:

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))

find application and shut it down, apache running?