Tuesday, October 17, 2017

Apache - Restricting a path in web server

In case you need to restrict a particular virtual path on Apache, you need to add following code to your httpd.conf or apache2.conf file:

<Location "/bin/path">
AuthUserFile C:/Apache/users
AuthName "Restricted Files"
#AuthGroupFile /dev/null
AuthType Basic
Require valid-user
</Location>

AuthUserFile- is the location of password file. You can define your custom path. The value provided here is just for illustration purpose. For Linux it can look like - "/etc/users"

If you want to provide access to usergroups then you can use AuthGroupFile, otherwise you should comment it.

AuthType- Various methods of authentication are available. It may be any of - None, Basic, Digest and Form.

Creating users for access- Run below command

htpasswd -c /etc/mysite/users mysite-new-user

AuthType Basic is not a secure way for authorization. Instead use Digest method with SSL.

You can also authenticate users from LDAP or DB. Refer the documentation at- https://httpd.apache.org/docs/2.4/howto/auth.html


No comments:

Post a Comment

CDN | Clearing Cloudflare cache

In order to clear Cloudflare cache automatically via code, follow below steps: 1. Develop Custom TransportHandler Develop a custom Trans...