I’ve been setting up a web server for my latest project – a Node.js / Express app. All was going well – I spun up a droplet on DigitalOcean, installed NVM, Node, Git, MongoDB and deployed and configured my app. Then I decided to add Nginx into the stack to act as a reverse proxy and serve my static files, and I hit a roadblock. For some reason Nginx was not picking up the server blocks I configured in /etc/nginx/sites-available/ (and enabled in /etc/nginx/sites-enabled/). I knew Nginx was working as it was correctly serving the ‘Welcome to Nginx’ page, but regardless of what I tried or how I adjusted the virtual hosts files, it wouldn’t send the requests to my Node app. It was baffling.
I started going through all the different Nginx files and when I opened the /etc/nginx/nginx.conf file, I noticed that at the bottom it included this line:
That pushed me in the right direction and made me realize that the sites-enabled directory was not read by Nginx at all and as a result the server blocks were ignored. Simply adding
as the last line in the nginx.conf file fixed the problem and the virtual hosts were finally being correctly recognized. Here’s what the entire nginx.conf file looks like (before any other configuration and tweaks):
error_log /var/log/nginx/error.log warn;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
access_log /var/log/nginx/access.log main;
I find it strange that the sites-enabled folder is not included by default since that is the location where you are supposed to configure your server blocks. But there you have it.