LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   (SOLVED) Apache2 basic authentication not working (https://www.linuxquestions.org/questions/linux-server-73/solved-apache2-basic-authentication-not-working-4175458103/)

beliya 04-14-2013 09:03 AM

(SOLVED) Apache2 basic authentication not working
 
Hello.

I am trying to set up Apache2 basic authentication for the main web server directory /var/www but it's not working.

I create password file with htpasswd, then put .htaccess file in /var/www with the following content:

AuthType Basic
AuthName "Restricted Files"
AuthBasicProvider file
AuthUserFile /etc/apache2/passwd
Require user user1

I've also got this in my httpd.conf

<Directory /var/www>
Options Indexes FollowSymLinks
AllowOverride AuthConfig
</Directory>

.. The site opens normally, end it does not require login/password authentication.

However, if I put the same .htaccess file in /var/www/lock and change the line <Directory /var/www> in httpd.conf to <Directory /var/www/lock> the server does require a password when the user enters hostname/lock .

How can I lock the whole /var/www ?
I would like to provide access to my webserver for some users and would love if each one could make his own locks (using .htaccess) so that I don't have to edit httpd.conf every time, anyone wants to lock some directory.

Thanks in advance for helping me.

Regards,
Beliya

beliya 04-14-2013 09:52 AM

Got it working
 
I got /var/www locked by removing the lines I had in httpd.conf and adding the following to ports.conf

<VirtualHost *:80>
ServerName hostname
ServerAlias hostname
DocumentRoot "/var/www"
<Directory "/var/www">
Options -Indexes
Order allow,deny
Allow from all
AllowOverride AuthConfig
AuthType Basic
AuthName "Basic Authentication"
AuthUserFile /etc/apache2/passwd
Require valid-user
</Directory>
</VirtualHost>

If anyone knows how to make each directory in /var/www locked with basic authentication and .htaccess I will really appreciate it if you share =)
I want each user to be able to self-lock his/her files, so that I don't have to touch server main config files every single time.

Habitual 04-14-2013 10:18 AM

"World Famous" htaccess tips and tricks http://corz.org/serv/tricks/htaccess.php

jeffmonte 04-14-2013 11:21 AM

How to create two lock files?
 
I am sorry, I did a wrong post here.

beliya 04-14-2013 12:51 PM

Everything works
 
Hey Habitual. Thanks for that guide, it's a nice one.
I got the things I wanted running.

Apparently it didn't worked before because the options were not in <VirtualHost ..> .. </VirtualHost>.

I now have the following virtualhost directive in my ports.conf file:

<VirtualHost *:80>
ServerName host
ServerAlias host
DocumentRoot "/var/www"
<Directory "/var/www">
AllowOverride AuthConfig
</Directory>
</VirtualHost>

The guide also mentions it:
You can also make this change inside a virtual host, which would normally be preferable.

So I guess.. that's the right way to do it =)

Regards,
Beliya


All times are GMT -5. The time now is 01:51 AM.