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.
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.
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 .
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With