Apache - Restrict access to certain directory by IP
Apache, Debian, Hacks
You can use this method to allow certain ip’s to access certain directories or to deny certain ip’s to access certain directories, its up to you how you want to protect that directory. In this example im gonna show you how to restrict access to a directory named “restricted” to a single ip, so when any other ip that is not in the list tries to access that directory it will get a page saying
Forbidden
You don’t have permission to access /restricted on this server.
The explanations work on Debian with Apache2 tested by me, but also it should work on any other OS and Apache2 version. Here is how you do it: you need to edit the following file /etc/apache2/sites-available/default and you do that with the following commmand:
nano /etc/apache2/sites-available/default
now at the end of the file on top of </VirtualHost> you need to add the following:
<Directory “/var/www/restricted/”>
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 1.1.1.1
</Directory>
replace “1.1.1.1″ with your ip and “/var/www/restricted/” with the path to the directory you want to restrict access to.
Now press ctrl+x and then Y to confirm and save the modifications. Now we need to reload the config file with the following command and we are done.
/etc/init.d/apache2 reload
Tags: Apache, Debian, forbidden, restric accessRelated posts
Wednesday, February 27th, 2008 at 11:26 am and is filed under Apache, Debian, Hacks. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.






