Block IP Address From Website On Apache
There are 3 ways to block (ban) IP address from accessing website in Apache: Modify httpd.conf, redirect IP to another predefined page, and using .htaccess.
The below statement assumes we will block or ban IP 188.8.131.52 from port 80.
1. Setting httpd.conf to block
Add these settings in httpd.conf:
NameVirtualHost 184.108.40.206:80 <VirtualHost 220.127.116.11:80> ServerName 18.104.22.168 <Location /> Order Allow,Deny Deny from all </Location> </VirtualHost>
2. Redirect IP to another page
Also set this in httpd.conf, Configuration as:
NameVirtualHost 22.214.171.124:80 <VirtualHost 126.96.36.199:80> ServerName 188.8.131.52 DocumentRoot "/srv/www/default" </VirtualHost>
3. Setting .htaccess
If you want to block IP from some bad users, add this in your .htaccess.
Order Deny,Allow Deny from 184.108.40.206
To block a IP range, for example 12.34.56.x, like this:
Order Deny,Allow Deny from 12.34.56. Allow from all