Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache: Restrict access to specific source IP inside virtual host

Tags:

apache

apache2

I have several named virtual hosts on the same apache server, for one of the virtual host I need to ensure only a specific set of IP addresses are allowed to access.

Please suggest the best way to do this. I have looked at mod_authz_hosts module but it does not look like I can do it inside virtual host.

like image 556
frameworksnow Avatar asked Oct 31 '13 16:10

frameworksnow


People also ask

How do I whitelist an IP in Apache?

Apache makes it easy to whitelist IP access to certain locations of your website and deny traffic to all other IP addresses. You can add the following to your /etc/apache2/apache2. conf file.

What is the syntax in Apache to restrict access to a web site and only grant access from a specified list?

If you wish to restrict access to portions of your site based on the host address of your visitors, this is most easily done using mod_authz_host .


1 Answers

The mod_authz_host directives need to be inside a <Location> or <Directory> block but I've used the former within <VirtualHost> like so for Apache 2.2:

<VirtualHost *:8080>     <Location />     Order deny,allow     Deny from all     Allow from 127.0.0.1     </Location>      ... </VirtualHost> 

Reference: https://askubuntu.com/questions/262981/how-to-install-mod-authz-host-in-apache

like image 141
Neil C. Obremski Avatar answered Sep 23 '22 17:09

Neil C. Obremski