Click to See Complete Forum and Search --> : .htaccess in a virtual host ?


sfahey
10-26-2002, 05:49 PM
Hi

Does anybody no how-to configure apache to use .htaccess in a virtual host ?

thanks

a bit stuck :)

blizz
10-26-2002, 09:11 PM
Hi,

For our example to protect the directory:

http://www.yourdomain.com/personalstuff/

To the web server this is the directory:

/etc/home/janedoe/www/personalstuff/

To do this we place a .htaccess file in that directory. Create one in notepad or something and ftp to the users directory that you wish to protect. Keep in mind that all sub-directories beneath this dir level will require htaccess login as well.
The file you make will contain:

AuthUserFile /etc/home/janedoe/www/personalstuff/.htpasswd
AuthGroupFile /dev/null
AuthName Somewhere Neat
AuthType Basic

<Limit GET POST>
require user trwrc
</Limit>

Now after you have created the .htaccess file and placed it in the directory you wish to protect you need to specify who is allowed? So now create an .htpasswd file in the AuthUserFile place above (/usr/home/janedoe/).

To create the .htpasswd file for my example, I login at my server and at terminal window cd to etc/home/janedoe

cd /etc/home/janedoe/www/personalstuff

Then use the htpasswd program with the -c switch to create your .htpasswd file in the current directory. Type:

htpasswd -c .htpasswd trwrc

To create the file and add "trwrc" as the first user. The program will prompt you for a password, then verify by asking again. You will not see the password when entering it here.

To add or allow more users simply add the username to the .htaccess file. This time I added Newuser:

<Limit GET POST>
require user trwrc
require user Newuser
</Limit>


Now -
Login as before to the right dir and use the same command without the -c switch:

#> htpasswd .htpasswd Newuser

This will add the username "Newuser" to your .htpasswd file and of course prompt for password.

Done with .htaccess set-up

Example:
<VirtualHost 72.56.22.137>
DocumentRoot /home/janedoe/www/
ServerName yourdomain.com
ServerAlias www.yourdomain.com
ScriptAlias /cgi-bin/ /home/janedoe/cgi-bin/
<Directory "/home/johnsmith/www/personalstuff">
AllowOverride All
</Directory>
</VirtualHost>

That should get you started.

sfahey
10-27-2002, 01:35 PM
Thanks for that!

I was OK with the first half; it was the directory container in the v-host that was throwing me of track.

Question: with the v-host configuration that you suggested it gives me the password dialogue box, but when I enter the password it ignores it.

After doing some reading, I’m guessing it has something to-do with httpd.conf on lines 431 and 462. here’s what I have and its still not working…?

-----------------------------------------------------------------------------------------------

#
# Each directory to which Apache has access, can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# permissions.
#
<Directory />
AuthUserFile /etc/httpd/passwd
AuthGroupFile /etc/httpd/group

Options -FollowSymLinks +Multiviews
AllowOverride All

</Directory>

------------------------------------------------------------------------------

#
# This controls which options the .htaccess files in directories can
# override. Can also be "All", or any combination of "Options", "FileInfo",
# "AuthConfig", and "Limit"
#
AllowOverride All

#

Hope you can help a little?
Right, I’m getting back to my Linux books :)

Thanks

sfahey
10-27-2002, 05:57 PM
this is out my error log, if it helps

[Sun Oct 27 21:27:43 2002] [error] [client 192.168.0.42] shaun: not a valid FDN: /members/index.html

sewer_monkey
10-29-2002, 12:50 AM
Try adding this to the <Directory> directive:

Require valid-user