Showing posts with label apache. Show all posts
Showing posts with label apache. Show all posts

Wednesday, October 3, 2012

Apache: fall-back mechanism

 

This is the recent requirement that i had faced w.r.t. virtual hosts.

  1. at a given location see if the static resource exist
  2. if it exist then serve form that location
  3. otherwise fallback to a default location

after a day of investigation… this was the solution i finally discovered

 

NameVirtualHost *:81
#telling virtual host to listen on this port
<VirtualHost *:81>
ErrorLog logs/rewrite-log
CustomLog logs/rewrite-log combined
DocumentRoot E:/proj/nono2_2_10_3/config/
LogLevel debug

<IfModule rewrite_module>
RewriteLog logs/rewrite.log
RewriteLogLevel 3
</IfModule>

RewriteEngine on
    #if the file at the below path doesnt exist then the rule applies. Both these are part of the same rule
RewriteCond %{DOCUMENT_ROOT}httpd/templates-mobile/js/$3 !-f
    #rule is to serve the files from default templates folder and skip the next rule (see s=1). Make this rule as the last rule(see L)
    #note the $1,$2,$3 are interpreted from he below rule. Each ‘()’ represents $n. where n increments per bracket
    # the above rewriteCond take $1,2,3 from this rule below
RewriteRule ^(/ui)(/tpl/js)(.+)$ %{DOCUMENT_ROOT}httpd/templates/js/$3 [L,S=1]
    #serve from templates-mobile folder     
RewriteRule ^(/ui)(/tpl/js)(.+)$ %{DOCUMENT_ROOT}httpd/templates-mobile/js/$3 [L]

</VirtualHost>




Hope this helps somebody…

Monday, September 5, 2011

Configure Apache

We can use apache to serve static resource; infact apache is meant for this. Apache can cache data so that accessing resources is very quick. Proxy pass is the best way to do this.

<VirtualHost *:80>
ServerAdmin abc@y.com
DocumentRoot /root/cacheContent
<IfModule rewrite_module>
RewriteLog logs/rewrite.log
RewriteLogLevel 3
</IfModule>

ProxyRequests off
ProxyPass /context/css/ !
ProxyPass /context/ http://10.10.11.176:8080/backendContext/
ProxyPassReverse /context/ http://10.10.11.176:8080/backendContext/

CacheEnable disk /
CacheEnable mem /

<IfModule mod_cache.c>
<IfModule mod_disk_cache.c>
CacheRoot /root/cacheContent/
CacheEnable disk /
</IfModule>
</IfModule>

</VirtualHost>

So this is how it works. When ever u get /context on this ip send it to 10.10.11.176/backendContext. When ever u have static resources dont get it from the bakendContext. So in this case it gets it from /root/cacheContext/.