I uploaded a nodejs file that crashed the server due to an infinite loop. In a panic, I stopped the EC2 instance and started it again. This gave me a new IP address.
I updated the registrar details for the domain name with the new IP. When visiting the IP in the browser, I saw the NGinx welcome screen.
I then changed the conf file for the sites-available/domain.com, to add the new IP in the server block redirect. After doing this, the site timesout.
I tried removing the IP from the sites-available/domain.com and still the site timesout and I cannot even ping the IP or see the Nginx welcome page.
When trying the following
sudo nginx -c /etc/nginx/nginx.conf
I get this error:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Unknown error)
nginx: [emerg] bind() to [::]:443 failed (98: Unknown error)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Unknown error)
nginx: [emerg] bind() to [::]:443 failed (98: Unknown error)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Unknown error)
nginx: [emerg] bind() to [::]:443 failed (98: Unknown error)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Unknown error)
nginx: [emerg] bind() to [::]:443 failed (98: Unknown error)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Unknown error)
nginx: [emerg] bind() to [::]:443 failed (98: Unknown error)
nginx: [emerg] still could not bind()
So I ran
grep -r listen /etc/nginx/*
I could see that the default and the domain.com 'sites-available' were both listening on port 80, 443 etc.
I deleted the default file from sites-available and restarted nginx. Now I only see the domain.com listening on port 80, 443 etc.
Still, nothing is loading when pinging the IP or the domain name in the browser or in terminal. I can ssh though.
I've also restarted UFW and ensured I enable Nginx Full etc., it's not a firewall issue. It's something to do with Nginx, I'm 99% sure.
EDIT I should add that this is not a UFW issue. That's working fine and allows NGINX Full, as well as HTTP and HTTPS
Additionally, when I visit the server IP address in the browser, I am redirected to the domain name, but very very slowly. Then I get a timeout. So something is happening...
Please help, I've tried everything reasonable that I've found from hours of googling!