We recently installed the (to this time) newest nginx version 1.17 on a new machine. The created configurations in sites-available were symlinked to sites-enabled, but nginx wasn’t serving any of the domains.
The crux here, nginx used the different directory conf.d to store a catch-all default configuration. This configuration matched all incoming requests and took over the handling for all requests and responses.
nginx Series Overview
- How To Install the Newest Version of Nginx on Ubuntu
- How to Run GitLab with Self-Signed SSL Certificate
- How to Fix Reponse Status 0 (Worker Process Exited on Signal 11)
- Redirect Only Root URL Path
- Remove an App/Domain from Sites-Enabled
- How to Serve a Static HTML Page
- Is Running but Not Serving Sites
- How to Fix Unknown "connection_upgrade" Variable
How nginx Configurations Work
Nginx keeps configurations located in the sites-available directory private and won’t route them to the Internet. Adding a configuration to the sites-enabled directory will make it publicly available.
Nginx allows you to support more than one location for configuration files. A second way to configure domains: the conf.d directory.
The difference here: any file located in the conf.d directory will be picked up by nginx and routed to the Internet. If you’d want to take a domain offline, you have to remove the configuration from the conf.d folder.
Check Your nginx Configuration
Check whether you have a conf.d directory in /etc/nginx that contains a default configuration.
If the conf.d directory is present, you should check nginx’s configuration whether it includes the sites-enabled folder:
nano /etc/nginx/nginx.conf
You’re interested in nginx’s virtual host configuration. Nginx will likely search the conf.d and sites-enabled directories for configurations. Depending on the order, nginx may find the “gotta catch ’em all“ config first.
The content of your nginx.conf file may look like this:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*; # <-- ensure this line if you want “sites-enabled” to work
}
If you placed your domain’s configuration files into the sites-available and sites-enabled directories, the default config from conf.d may overlay them.