May 18, 2012
tom

How can I password prompt certain IPs and allow all others free access using Apache?

Question

SOLVED:
The idea is that if the visitor comes from China they have to pass a basic authentication. If you have any other IP address you can visit the site without being hassled (including proxies)

//1400 rules....
SetEnvIf Remote_Addr 222.249.128.0/19 china
SetEnvIf Remote_Addr 222.249.160.0/20 china
SetEnvIf Remote_Addr 222.249.176.0/20 china
AuthType Basic
AuthName "Restricted"
AuthUserFile /www/passwd/users
Require valid-user
Order allow,deny
Allow from All
Deny from env=china
Satisfy any
Asked by Moak

Answer

This is the code I use to allow all users, deny the ones form China and password prompt those:

AuthType Basic
AuthName "Restricted"
AuthUserFile /home/.htpasswds/.htpasswd
Require valid-user
Order Allow,Deny
Allow from all
deny from 58.14.0.0/15
....
deny from 222.249.192.0/18
satisfy any
Answered by Moak

No related posts.

Leave a comment