How to Restrict Apache Directory access in CentOS 6.7

To Restrict Apache Directory access in CentOS 6.7  

A Directory contains a list of files that can be stored and retrieved for later use. For restricting access to the entire directory contents, specific directory content and specific directory contents for specific IP's by other users, this confiugration procedure can be done. In this tutorial the configuration process of restricting access to directory contents using Apache on CentOS 6.7 is explained as follows. 

 

Configuration procedure

To proceed with the configuration process, check the Apache status by running the following command. 

[root@domain1 Desktop]# service httpd status

Next go to web content directory path of Apache and list the directory contents are presented properly.

[root@domain1 Desktop]# cd /var/www/html/fold/
[root@domain1 fold]# ls -l
total 16
drwxr-xr-x 3 root root 4096 Oct  9 00:44 four
drwxr-xr-x 3 root root 4096 Oct  9 00:43 one
drwxr-xr-x 3 root root 4096 Oct  9 00:44 three
drwxr-xr-x 3 root root 4096 Oct  9 00:43 two

Locate the Apache configuration file and make the below changes to block all contents of the particular directory. 

[root@domain1 Desktop]# vim /etc/httpd/conf/httpd.conf
 Options -Indexes FollowSymLinks

Restart the Apache service and check it from browser. All the contents related to the directory are blocked. 
apache service

To revert the changes, do the following changes in the Apache Configuration file. 

[root@domain1 Desktop]# vim /etc/httpd/conf/httpd.conf
 Options Indexes FollowSymLinks

Restart the Apache service and check it from browser. Now all contents will displayed for the other users to access.
contents displayed

To restrict a particular directory, perform the following steps in the Apache Configuration file and save the following changes in the file. Exit the file. 

[root@domain1 Desktop]# vim /etc/httpd/conf/httpd.conf
<Directory /var/www/html/fold/four>
       AllowOverride All
       order deny,allow
        deny from all
</Directory>

Restart the Apache service and check the changes in the browser. The particular file will be blocked and cannot be accessed as configured. 
apache service forbidden

The remaining files of the particular folder is displayed and can be accessed without any hurdle. 
folder hidden

To restrict particular directory for particular IP’s, perfom the following steps in the Apache configuration file. Save and exit the file. 

[root@domain1 Desktop]# vim /etc/httpd/conf/httpd.conf   
<Directory /var/www/html/fold/four>
       AllowOverride All
       order allow,deny
       allow from all
       deny from 192.168.7.206
</Directory>

Restart the Apache service and check the changes from the client machine. 
client machine

 

 

Check if all the contents of the directory and is accessible from all IP ranges.

index page

This concludes the configuration procedure of restricting access to directory contents using Apache on CentOS 6.7


Thank you! for using Linux Help.

You find this tutorial helpful? Share with your friends to keep it alive.
For more help topics browse our website www.linuxhelp.com
Be the first to comment, we value your suggestions. For further queries please comment below.

Tags: Apache CentOS
user image Author :  Lawrence