How to configure NGINX server to block access using server IP

In this tutorial, I will try to explain how we can block access to the server when someone tries to access the server from the IP address in browser.

After following the below steps your server will only be accessed with domain name in browsers not the IP address.

1. Create a file 1.2.3.4.conf in /etc/nginx/conf.d/. (Replace 1.2.3.4 with your server’s public IP). Then add the following to your file 1.2.3.4.conf

server {
    server_name "1.2.3.4";
    return      444; 
}

2. Restart NGINX service.

sudo systemctl restart nginx 

Leave a Reply

Your email address will not be published. Required fields are marked *