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.

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.

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.

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

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.

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

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

Tag : Apache CentOS
FAQ
Q
Why do I get complaints about a redefinition of "struct iovec" when compiling under Linux?
A
This is a conflict between your C library includes and your kernel includes. You need to make sure that the versions of both are matched properly. There are two workarounds, either one will solve the problem:

Remove the definition of struct iovec from your C library includes. It is located in /usr/include/sys/uio.h. Or, Add -DNO_WRITEV to the EXTRA_CFLAGS line in your Configuration and reconfigure/rebuild. This hurts performance and should only be used as a last resort.
Q
Is there any more information available on Apache httpd?
A
Indeed there is. See the main Apache web server site. There are also many books about the Apache HTTP Server available as "http://httpd.apache.org/"
Q
Where can I get Apache httpd?
A
You can find out how to download the source for Apache at the main Apache web server site as "http://httpd.apache.org/"
Q
May I use the Apache logo on my product or Web site?
A
You may NOT use any original artwork from the Apache Software Foundation, nor make or use modified versions of such artwork, except under the conditions in the Apache Trademark Policy document as "http://www.apache.org/foundation/marks/"
Q
How do I submit a patch to Apache httpd?
A
Detailed information for submitting bug reports and patches may be found in the Apache HTTP Server developer documentation as "http://httpd.apache.org/dev/"