apache2 basic auth / ip based authentication

As I keep forgetting how this works, here’s an example config that will require basic auth for the “/” URI while permitting basic-authless access to “/test” for IPs listed in the Allow from statement (other source IPs will still be able to access stuff in “/test” if proper basic authentication info is provided with the request):

# httpd.conf 

# basic auth für "/" und "/test" except for IPs listed in the "Allow from..." Statement 

<Location /> 

   AuthType Basic 

   AuthUserFile /etc/httpd/conf/htpasswd 

   AuthName "Authorized Users Only" 

   require valid-user 

</Location> 

<LocationMatch /test/*> 

   Order Deny,Allow 

   Satisfy any 

   Deny from all 

   Require valid-user 

   Allow from AAA.XXX.YYY.ZZZ 

</LocationMatch> 

Leave a Reply

Your email address will not be published.