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>
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