How to disable direct ip access on CentOs VPS

Disabling direct IP access prevents  anyone from accessing your website using the IP address.
If anyone tries to access your site using the IP address then a 403 Forbidden error will be shown.

To disable direct IP access you would have to edit the virtual host file

sudo vi /etc/httpd/conf.d/example.com.conf

Modify the above command based on your domain name and location of virtual host file.
conf.d directory is the default location of the virtual host file which I used in one of my earlier tutorials about virtual host.

Paste the code given below in your virtual host file. Replace 104.225.220.168 with your server’s IP address

<VirtualHost *:80>
    ServerName 104.225.220.168
    Redirect 403 /
    ErrorDocument 403 "No"
    DocumentRoot /dev/null/
    UseCanonicalName Off
    UserDir disabled
</VirtualHost>

disable direct ip access centos

After editing the virtual host file restart the server

sudo systemctl restart httpd

Now accessing the site via IP address would lead to 403 forbidden message being displayed
forbid direct ip access in vps

Previous Post
How to disable root login on CentOs VPS
Next Post
CentOs VPS Setup To Host Your Website – Step By Step Guide

Related Posts

Leave a Reply

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

Fill out this field
Fill out this field
Please enter a valid email address.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

alert('dsf'); console.log("dsdsdsd");