apacheapache2

Apache: Restrict access to specific source IP inside virtual host


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.


Solution

  • 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