How to block by ip with Apache

991 Views Asked by At

I am trying to place apache restrict by ip.

I tested on my IP if by blocking myself or accept only the other IP.

Apache was restarted, i really don't know which could be the problem

I could accessed on the page despite of the restriction

All examples which i found on web as below :

<Location /home>
        SetEnvIf X-Forwarded-For ^xxx\.xxx\.xxx\.xxx access
        Order allow,deny
        Satisfy Any
        Allow from env=access
</Location>


<Location /home>        
        Order Deny,Allow
        Deny from All
        Allow from xxx.xxx.xxx.xxx
        Deny from All
        Satisfy Any
</Location>

<ProxyMatch "/home/*" >
    Order Deny,Allow
    Deny from all
    Allow from xxx.xxx.xxx.xxx
</ProxyMatch>


<LocationMatch "/home">
       Order Allow,Deny
       Allow from all
       SetEnvif X-Forwarded-For "xxx\.xxx\." DenyAccess
       Deny from env=DenyAccess
</LocationMatch>


<Location "/home">
       Order Allow,Deny
       Allow from all
       SetEnvIf X-Forwarded-For ^xxx\.xxx\. denyAccess
       Deny from env=denyAccess
</Location>


<Location "/home">
        SetEnvIf X-Forwarded-For ^xxx\.xxx\. access
        Order allow,deny
        Satisfy Any
        Allow from env=access
</Location>

Thanks

2

There are 2 best solutions below

1
On

You can do it via Require not ip xxx.xxx.xxx.xxx directive Documentation here: https://httpd.apache.org/docs/2.4/howto/access.html

1
On

Apache 2.4 has a differing structure using Require

<Files /home>
    Require all granted
    Require not ip xx.xx.xx.xx
</Files>