Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache deny from list of ip's in external file

Tags:

apache

I'd like to maintain a file which includes a list of ip's which are blocked from using a site. I understand deny from can be used to achieve this (e.g Deny from 127.0.0.1 10.0.0.1 some.other.ip.address).

However, I'd like an external file so that an individual who does not have access to the config can update a txt file with ip's and this will then be included in the deny from.

Does anyone have any reccomendations on how this can be achieved? Any help is greatly appriciated.

like image 398
r1901156 Avatar asked May 24 '12 13:05

r1901156


People also ask

How to block ip address using. htaccess file?

In this tutorial, you've learned the easy way to block or allow visitors from specific countries. All you need to do is generate the country's IP address via Country IP Blocks, then insert an access control list (ACL) into your . htaccess file.

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

Look at the Apache Include directive:

http://httpd.apache.org/docs/2.2/mod/core.html#include

You can create a seperate configuration file contain you denied list and include in any other configuration file i.e a site in sites-available. Example usage below:

In /etc/apache2/sites-enabled/yoursite.conf

<VirtualHost *:80>
...

Include /etc/apache2/sites-access/yoursite.conf

...
</VirtualHost>

In /etc/apache2/sites-access/yoursite.conf

order allow,deny
deny from 10.0.0.1
allow from all
like image 192
William Greenly Avatar answered Sep 24 '22 05:09

William Greenly