Activities

January 2013
M T W T F S S
« Dec   Mar »
 123456
78910111213
14151617181920
21222324252627
28293031  

Apache – Mod-jk : How to limit the url access to certain IP’s

One of the client needs to limit the application admin area to certain ips’ that he suppose to be used. He uses JAVA application in Linux server.

System settings are,
a. Apache Webserver [frontend]
b. Mod-jk ( AJP connector to tomcat)
c. Tomcat Java application server.

In this mixed settings .httacess will not work till all the request to this hosting area handled by tomcat virtual space. So any of location directive will not work. After goggling I found a thread showing it can be controlled through Re-write rules.

I want to protect the area http://mydomain.com/admin. Here is the rules that you need to added in apahce config.

#touch /usr/local/apache/logs/rewrite.log
#chmod 777 /usr/local/apache/logs/rewrite.log
Then open the virtualhost config. file and added the following lines.
RewriteEngine    on
RewriteLog       /usr/local/apache/logs/rewrite.log
RewriteLogLevel  0
RewriteCond   %{REMOTE_ADDR}  61.7.2.52                        [OR]
RewriteCond   %{REMOTE_ADDR}  12.66.40.2                     [OR]
RewriteCond   %{REMOTE_ADDR}  2.31.24.1
RewriteRule   ^(/admin.*)    $1                                  [PT,L]
RewriteRule   ^/admin.*      -                                   [F]

Hurrah !! That’s it

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>