how to disable direct visiting on website with its server IP address with both and

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

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

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

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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>
    Redirect 403
    DocumentRoot /path/to/file

You’ll need to change the 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 “default_server” parameter so that all non available server requests goes to this server block which throws 444 error. The “default_server” parameter cannot be present in any other server block.


Regards, KDSys