While trying to create a new website last night I ran into the issue of not being able to bring it online. Instead, when trying to access the domain nginx would redirect the browser to the website marked as default_server in my nginx configs. This is normal behavior when a domain points to your server but you don’t have a server set up in nginx for that domain, or if you access the host via IP instead of a domain. I checked permissions for the files (correct), I checked that nginx was running under the correct user (correct), and I checked that the other websites were still up (they were), I checked that I had properly symlinked the config from sites-available to sites-enabled (looked good but it was the root problem in the end). I decided to try removing a site and and re-adding it to see what would happen. After restarting ngnix, both the new site and the one I tested with are now not working. Being that it was 2 in the morning and obviously a great time for me to be working on a server, I felt the best course of action would be to remove and re link every single link in sites-enabled. None of the sites would come up with the error “connection refused”. nmap showed 80 and 443 as closed on the server. I tried setting a site to display on port 8000 and that also stayed closed. No matter what I did i could not get a error to show or any ports to open. Even after backing up my files, purging nginx, and reinstalling I was not getting new results.
The issue ultimately was the way I was symlinking. instead of running
ln -s /etc/nginx/sites-available/config /etc/nginx/sites-enabled/config I was running (from sites-available as my working dir)
ln -s config ../sites-enabled/config. Unbeknownst to me, nginx wont throw any errors or warnings about bad symlinking and will ignore any improper symlinks in sites-enabled. Furthermore, when there are no active configs telling ngnix to use ports 80, 443, etc., it will not bind those ports (obviously).