Question

how to disable direct visiting on website with its server IP address with both http://1.2.3.4 and https://1.2.3.4

Posted March 21, 2020 122 views
DNS

We can disable direct visiting on website with its server IP address with below method —>

ServerName 1.2.3.4         
ServerAdmin webmaster@localhost         
DocumentRoot /var/www/html          
<Location />                 
Order Allow,Deny                 
Deny from All         
</Location>  

but it can still visit-able with https://1.2.3.4… .
Can any one please tell how to prevent visits with
http://1.2.3.4 and https://1.2.3.4

edited by MattIPv4

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hi @metaproton1,

Depending on the WebService you are using the answer varies. If you are using Apache as a WebService you can use the following way:

Additionally, this mini tutorial will be for Ubuntu. If you are using CentOS let me know and I’ll provide steps for it as well :

  • Apache

You’ll need to create a virtual configuration - Vhost.
Create a new config file in the sites-available directory:

sudo nano /etc/apache2/sites-available/direct.conf

In the file add the following :

<VirtualHost *:80>
    ServerName xxx.xxx.xxx.xxx
    Redirect 403
    DocumentRoot /path/to/file
</VirtualHost>

You’ll need to change the xxx.xxx.xxx.xxx with your actual IP address and the /path/to/file with the path to the file being the file you wish people to see when they access the IP address. Once you have saved the file, type

sudo a2ensite direct

and restart your server:

sudo apache2 restart

That’s it, you’ve now redirected access of your IP address to a certain file.

If you wish to completly deny it, add the DocumentRoot to be /dev/null

  • Nginx

You can add this server block to your configuration.

server {
    listen      80 default_server;
    server_name "";
    return      444;
}

You need to specify “defaultserver” parameter so that all non available server requests goes to this server block which throws 444 error. The “defaultserver” parameter cannot be present in any other server block.

444 : CONNECTION CLOSED WITHOUT RESPONSE

Regards,
KDSys

Submit an Answer