NGINX Catch All Server Name

nginx catch all server name

NGINX will handle all requests sent to your domain name. However, sometimes, users might link to or request a URL by your website’s IP. How do you handle such requests? The solution is to simply create a catch all server name to handle these requests. Let us take a look at how to configure NGINX catch all server name for your website/application.


How to Configure NGINX Catch All Server Name

Here are the steps to configure NGINX catch all server name for your website/application.


1. Open NGINX config file

Open NGINX config file in a text editor. You will find NGINX config file at one of the following locations, depending on the type of installation


$ sudo vim /etc/nginx/nginx.conf



2. Setup NGINX Catch All Server Name

Create a server block in your config file. User ‘server_name _’ and the keyword default_server in your server config.

server {

   listen 80 default_server;
   server_name _;

   root /var/www/default;

For HTTPS, use listen 443 ssl default_server;

The above server block will act as a catch all server name. If you are creating separate config files for virtual hosts, then place the above code in one of those files.



3. Reload NGINX web server

Test the config file to ensure there are no errors.

$ sudo nginx -t


If you get no error message, reload NGINX server to apply changes.

$ sudo service nginx reload




That’s it! Now NGINX will even handle the requests made using only your website’s IP, as well as via links which use only your server’s IP address, automatically, without giving any errors.

About Sreeram Sreenivasan

Sreeram Sreenivasan is the Founder of Ubiq, a business dashboard & reporting platform for small & medium businesses. Ubiq makes it easy to build business dashboards & reports for your business. Try it for free today!