How to restrict particular file types in Apache directory in CentOS 6.7
To restrict particular file types in Apache directory in CentOS 6.7
In our previous article, we have explained about the configuration procedure of How to restrict Apache Directory Access in CentOS 6.7. This article will be briefed about how to restrict particular file types in Apache directory in CentOS 6.7. Apache directory contains so many file types will available to perform different task. This method is useful when it comes to allow only particular file types access for specific user or entire user.
Configuration procedure
Before proceeding to the configuration process, check the status of Apache in the target system.
[root@domain1 ]# service httpd status
Next locate the file content directory to restrict some specific files.
[root@domain1 ~]# cd /var/www/html/fold/one/
[root@domain1 one]# ls -l
total 664
drwxr-xr-x 2 root root 4096 Oct 9 00:43 f1
-rw-r--r-- 1 root root 27 Oct 9 00:42 file1.txt
-rw-r--r-- 1 root root 469423 Oct 10 00:20 lcommands.pdf
-rw-r--r-- 1 root root 11913 Oct 10 00:22 lin.png
-rw-r--r-- 1 root root 136723 Oct 10 00:20 linux.pdf
-rw-r--r-- 1 root root 5466 Oct 10 00:23 Red_Hat.jpg
-rw-r--r-- 1 root root 40612 Oct 10 00:26 ubu.jpg
Open the Apache configuration file and create rule to restrict specific files types in the directory. In this file, restrict some .pdf and .jpg file for the entire users. So files other than the restricted ones can be accessed by the user.
[root@domain1 ~]# vim /etc/httpd/conf/httpd.conf
Directory /var/www/html/fold/one>
order allow,deny
allow from all
< Files ~ " .(pdf|jpg)" >
deny from all
< /Files>
< /Directory>
Restart the Apache service.
[root@domain1 ~]# service httpd restart
Switch over to the browser and check the configuration from browser by accessing the index page of the directory.
Next try to access blocked files and the access will be blocked by the Apache service.
To restrict specific files types for particular IP. Open the Apache Configuration and enter the following content in the file. Save and exit the file.
[root@domain1 one]# vim /etc/httpd/conf/httpd.conf
< Directory /var/www/html/fold/one>
order allow,deny
allow from all
< Files ~ " .(pdf|jpg)" >
deny from 192.168.7.206
< /Files>
< /Directory>
Restart the Apache service.
[root@domain1 ~]# service httpd restart
Now to check the configuration procedure and the index page is displayed before setting the restriction access for client.
After setting the restriction access for client. The index page will be displayed like below.
While trying to access blocked files and the user will be forbidden to access the site.
Thus concludes the configuration procedure of restricting particular file types in Apache directory in CentOS 6.7.
Comments ( 0 )
No comments available