How to disable direct IP access in vestacp centos server

If you want to disable access to your website or domain through the IP address of your server then you can follow the steps below.

Log in to your server using putty (SSH).
After that you need to access httpd.conf file. The location of httpd.conf may vary. In this case – VestaCP is installed on Centos server and the location is- /home/admin/conf/web/
Use the following command to go into the directory which contains httpd.conf file
Note: If the username is something other than admin then replace admin with the appropriate username.

cd /home/admin/conf/web/

After this to edit httpd.conf file use the command given below

vi httpd.conf

Now you can edit the file using vi editor, below is an example of httpd.conf file

direct ip access apache

Add the code at the beginning of the file everything else remains the same.  Below is the code.

<VirtualHost 5.5.5.5:8080>

ServerName 5.5.5.5
Redirect 403 /
ErrorDocument 403 "No"
DocumentRoot /dev/null/
</VirtualHost>

Note: Replace 5.5.5.5 with your server IP address.

Save changes and then restart httpd using the below command.

service httpd restart

Now if any one types in your server’s IP address  then rror will be shown and your website will not be accessible using the IP address of the server.

Next Post
Centos 7 VPS setup to host a website : The first step

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.

Menu