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 22.214.171.124 from port 80.
1. Setting httpd.conf to block
Add these settings in httpd.conf:
NameVirtualHost 126.96.36.199:80 <VirtualHost 188.8.131.52:80> ServerName 184.108.40.206 <Location /> Order Allow,Deny Deny from all </Location> </VirtualHost>
2. Redirect IP to another page
Also set this in httpd.conf, Configuration as:
NameVirtualHost 220.127.116.11:80 <VirtualHost 18.104.22.168:80> ServerName 22.214.171.124 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 126.96.36.199
To block a IP range, for example 12.34.56.x, like this:
Order Deny,Allow Deny from 12.34.56. Allow from all