Wednesday 27 January 2016

How to Secure Specific URL in Apache

This article will help you secure specific url in Apache. For example our site has an url likehttp://tecadmin.net/admin/” and we need that only the authorized users or ips can access/admin/ section.

Setup IP Based Restriction on Specific URL

Step 1: Edit apache configuration file and add below entry in websites virtual host.
<Location /admin>
Order deny,allow
Deny from all
Allow from 192.168.10.111
Allow from 111.222.333.444
</Location>
Step 2: Save Apache configuration file and restart apache service.
# service httpd restart
Step 3: Try to access your site from any other ip. Also check from given ip in configuration file.

Setup User Authentication on Specific URL

Step 1: Edit apache configuration file and add below entry in website virtual host.
<Location /admin>
AuthUserFile /var/www/htpasswd/.htpasswd
AuthName "Password Protected Area"
AuthType Basic
Require valid-user
</Location>
Step 2: Create htpasswd file using below command.
# htpasswd -cm /var/www/htpasswd/.htpasswd myuser

New password:
Re-type new password:
Adding password for user myuser
Step 3:
Restart apache and access your site url. It will prompt for login details.
# service httpd restart
Thanks for using this article, I hope this article fulfill your needs. Click here to read more details about apache location directive.

No comments:

Post a Comment