Once you are comfortable setting up the virtual hosts, you will end up in a situation where you have a lot of domains pointing at the IP. In addition to the domains, you would also have the web server responding to the IP addresses it hosts, and many other unused subdomains of the domains pointing at it. We can take a look at this with a simple example, so you have http://www.example1.com
pointing at the IP address, you have configured a virtual host to handle the domains www.example1.com
and example1.com
. In such a scenario, when the user types in abc.example1.com
or an IP address the web server will not be able to serve the relevant content (be it 404 or some other promotional page).
For situations like the one above, one can utilize the default catchall virtual host that Nginx provides; here is a simple example where this default catchall virtual host serves a simple set of web pages.
The following is the code for sites-enabled/default.conf
:
server { listen 80 default; server_name _; location / { root /var/www/default; index index.html index.htm; } }