Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've website running in apache 2.2.3. Root directory of website contains three directories. I want to setup authentication for these directories as below

  1. only user1 can browse all pages

  2. user2 can only access mydomain.com/dir1/

  3. user3 can only access mydomain.com/dir2/

  4. user4 can only access mydomain.com/dir3/

I've tried below configuration but only user1 can browse website other users are unable to access website.

<directory /var/www/html/example>
        AuthUserFile /etc/httpd/user1-htpasswd
        AuthName "Resricted"
        AuthType Basic
        Require user user1
</directory>

<directory /var/www/html/example/dir1/>
        AuthUserFile /etc/httpd/user2-htpasswd
        AuthName "Resricted"
        AuthType Basic
        Require user user2
</directory>

<directory /var/www/html/example/dir2/>
        AuthUserFile /etc/httpd/user3-htpasswd
        AuthName "Resricted"
        AuthType Basic
        Require user user3
</directory>

Please guide me for the same. Thanks in advance.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

It should work if you put all your users login info in one passwd file and then do something like this (untested)

<directory /var/www/html/example/dir1/>
        AuthUserFile /etc/httpd/users-htpasswd
        AuthName "Resricted"
        AuthType Basic
        Require user user1
        Require user user2
</directory>

<directory /var/www/html/example/dir2/>
        AuthUserFile /etc/httpd/users-htpasswd
        AuthName "Resricted"
        AuthType Basic
        Require user user1
        Require user user3
</directory>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.