Password protect Apache2 folder

Don´t be shy, Linux is fun! =)
Post Reply
User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Password protect Apache2 folder

Post by ayu »

Well, I know how to password protect it in a regular manor

Example:

Code: Select all

<Directory /var/www/torrent>
        AllowOverride AuthConfig
        AuthName "Authentication Needed"
        AuthType Basic
        AuthUserFile /etc/.htpasswd
        AuthGroupFile /dev/null
        require user cats
</Directory>
But how do I allow only certain IP's? and block all others? and maybe only password protect for some IP's or only the outside of my network, etc?
"The best place to hide a tree, is in a forest"

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
18
Location: In your eye floaters.
Contact:

Post by bad_brain »

by using the deny/allow directives:

Code: Select all

deny from all
allow from 192.0.0.1 192.0.0.2 
you can also use CIDR notation like 192.0.0.0/16

works pretty much like iptables rules....you can use a deny or allow policy and set the exceptions then... :wink:

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

So it would be:

Code: Select all

<Directory /var/www/torrent>
        deny from all
        allow from 192.0.0.1 192.0.0.2 
        AllowOverride AuthConfig
        AuthName "Authentication Needed"
        AuthType Basic
        AuthUserFile /etc/.htpasswd
        AuthGroupFile /dev/null
        require user cats
</Directory> 
Kinda?
"The best place to hide a tree, is in a forest"

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
18
Location: In your eye floaters.
Contact:

Post by bad_brain »

yeup! :)

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

bad_brain wrote:yeup! :)
<3

ok...just assisted room mate in debugging his code...sleepy time T_T
"The best place to hide a tree, is in a forest"

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
18
Location: In your eye floaters.
Contact:

Post by bad_brain »

oops...forgot one line:


Code: Select all

<Directory /var/www/torrent>
        Order Deny,Allow
        deny from all
        allow from 192.0.0.1 192.0.0.2
        AllowOverride AuthConfig
        AuthName "Authentication Needed"
        AuthType Basic
        AuthUserFile /etc/.htpasswd
        AuthGroupFile /dev/null
        require user cats
</Directory> 
nighty-night...^^

User avatar
F4LSE
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 236
Joined: 02 Jul 2007, 16:00
16
Location: My Lab
Contact:

Post by F4LSE »

hey good thread. ive been experimenting with my server and i implemented the same stuff. very handy.

kudos to both of you :D

Post Reply