Keep Server Online
  
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
  
or
  
 
  
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
  
Thank You! Steffen
  
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
 |    |   
 | 
     Topic: Apache Reverse Proxy with caching and content freshness | 
 |   
| Author | 
  | 
 
pyli
 
  
  Joined: 03 Sep 2011 Posts: 4 Location: India
  | 
 Posted: Sat 03 Sep '11 22:08    Post subject: Apache Reverse Proxy with caching and content freshness | 
     | 
 
  | 
 
Hi all (Apache Experts)
 
 
 I am a noobie, trying to learn good things about Apache httpd server. 
 
 
Now i want to configure a reverse proxy with caching & deflation. But the rules are the performance has to be good over the network. All objects(resources) can be cached for a period of time say N or 1 month. But if there is modification or new representation in the origin server before the expiry time, the cache needs to have the new representation.
 
 
I am trying to implement it. I have tried to understand the various documents posted by many experts. But i don't get the desired results. 
 
I am posting the httpd.conf file here. 
 
 
Can some one guide me how to optimize this configuration. 
 
The major goal is to have good caching for a month.
 
But to fetch the new representation if it has changed in before the expiry time. And there should be no loss in Latency. 
 
 
I am trying to understand caching+validation and if there is a way to instruct the browsers not to cache but use the proxy cache instead. does 304 return code have impact on bandwidth?
 
 
Thanks in advance for advising me.
 
Regards
 
Pyli 
 
 
Apache Version = Apache2.2 
 
Installed on Windows Xp 
 
 
 	  | Code: | 	 		  NameVirtualHost  abc.dmn.com:8080
 
<VirtualHost  abc.dmn.com:8080>
 
      ProxyRequests off
 
      ProxyPass  / http://tomcatserver:8435/
 
      ProxyPassReverse / http://tomcatserver:8435/
 
</VirtualHost>
 
      
 
      <IfModule mod_cache.c>
 
            <IfModule mod_mem_cache.c>
 
               CacheEnable mem /
 
               CacheEnable mem http://tomcatserver:8435/
 
               MCacheRemovalAlgorithm LRU 
 
               MCacheSize 2000000 
 
               MCacheMaxObjectCount 100000 
 
               MCacheMinObjectSize 1
 
               MCacheMaxStreamingBuffer 9900000 
 
               MCacheMaxObjectSize 9900000
 
               CacheStoreNoStore On
 
               CacheStorePrivate On
 
               CacheIgnoreNoLastMod On
 
               CacheIgnoreCacheControl On
 
            </IfModule>
 
      </IfModule>
 
 
      <IfModule mod_expires.c>
 
       ExpiresActive On
 
       ExpiresDefault "access plus 1 month"
 
              
 
            <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|html|xml|class)$">
 
               ExpiresDefault "access plus 1 month"
 
               Header set Cache-Control  "no-cache,proxy-revalidate,must-revalidate,public"
 
            </FilesMatch>
 
 
       
 
      </IfModule>
 
 
 
      #Deflation
 
      <IfModule mod_deflate.c>
 
              AddOutputFilterByType DEFLATE text/plain
 
              AddOutputFilterByType DEFLATE text/html
 
              AddOutputFilterByType DEFLATE text/xml
 
              AddOutputFilterByType DEFLATE text/css
 
              AddOutputFilterByType DEFLATE image/svg+xml
 
              AddOutputFilterByType DEFLATE image/x-icon
 
              AddOutputFilterByType DEFLATE application/xml
 
              AddOutputFilterByType DEFLATE application/xhtml+xml
 
              AddOutputFilterByType DEFLATE application/rss+xml
 
              AddOutputFilterByType DEFLATE application/javascript
 
              AddOutputFilterByType DEFLATE application/x-javascript
 
       
 
              AddOutputFilterByType DEFLATE application/x-httpd-php
 
              AddOutputFilterByType DEFLATE application/x-httpd-fastphp
 
              AddOutputFilterByType DEFLATE application/x-httpd-eruby
 
       
 
              DeflateCompressionLevel 6
 
       
 
      # Netscape 4.X has some problems
 
              BrowserMatch ^Mozilla/4 gzip-only-text/html
 
       
 
      # Netscape 4.06-4.08 have some more problems
 
              BrowserMatch ^Mozilla/4\.0[678] no-gzip
 
       
 
      # MSIE masquerades as Netscape, but it is fine
 
              BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
 
       
 
      # Setup custom deflate log
 
              DeflateFilterNote Input instream
 
              DeflateFilterNote Output outstream
 
              DeflateFilterNote Ratio ratio
 
 
              LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
 
      # Example of log file (add to vhosts)
 
              CustomLog logs/deflate_log DEFLATE
 
      </IfModule>
 
 
 
 | 	 
  | 
 
  | 
 
| Back to top | 
 | 
 
James Blond Moderator
  
  Joined: 19 Jan 2006 Posts: 7442 Location: EU, Germany, Next to Hamburg
  | 
 Posted: Tue 06 Sep '11 21:41    Post subject:  | 
     | 
 
  | 
 
| I never used mod cache that way, but maybe you can use CacheLastModifiedFactor | 
 
  | 
 
| Back to top | 
 | 
 
pyli
 
  
  Joined: 03 Sep 2011 Posts: 4 Location: India
  | 
 Posted: Thu 08 Sep '11 2:54    Post subject:  | 
     | 
 
  | 
 
 	  | James Blond wrote: | 	 		  | I never used mod cache that way, but maybe you can use CacheLastModifiedFactor | 	  
 
 
Thanks James,
 
 
Do you think if i made the directive like this 
 
 	  | Code: | 	 		  
 
CacheLastModifiedFactor = 0.0 | 	   
 
 
a good option? I don't know how that's going to be. My guess is that it should be immediate. What is your opinion? | 
 
  | 
 
| Back to top | 
 | 
 
James Blond Moderator
  
  Joined: 19 Jan 2006 Posts: 7442 Location: EU, Germany, Next to Hamburg
  | 
 Posted: Thu 08 Sep '11 10:34    Post subject:  | 
     | 
 
  | 
 
I think the 0.0 is a good value.  Yepp the 0.0 schould be immediate. But as I told I never just mod cache so extrem with such a long caching time. I can just recommend to trial and error      Tell us if that works. | 
 
  | 
 
| Back to top | 
 | 
 
pyli
 
  
  Joined: 03 Sep 2011 Posts: 4 Location: India
  | 
 Posted: Sun 11 Sep '11 8:11    Post subject:  | 
     | 
 
  | 
 
 	  | Code: | 	 		  <IfModule mod_expires.c>
 
       ExpiresActive On
 
       ExpiresDefault "access plus 1 hour"
 
              
 
            <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
 
               ExpiresDefault "access plus 1 month"
 
               Header set Cache-Control  "no-cache,proxy-revalidate,must-revalidate,public"
 
            </FilesMatch>
 
 
      
 
      </IfModule>  | 	  
 
 
From the above code, i am trying to implement a freshness of proxy cache for a time period and specific URL contents that have the files names to expire after a certain time but they should revaildate to see if they are fresh.
 
 
www.example.com/Testapp/abc.jpeg 
 
 
But when i apply the above code, i don't see that happening for the above URL. the response headers says that this object expires in 1 hour and not 1 month. Also the cache-control is not set
 
 
Is there some thing wrong in the filesmatch block, or is there some over riding of the directives happening here. I am lost. | 
 
  | 
 
| Back to top | 
 | 
 
pyli
 
  
  Joined: 03 Sep 2011 Posts: 4 Location: India
  | 
 Posted: Thu 22 Sep '11 15:16    Post subject:  | 
     | 
 
  | 
 
Hi,
 
 
 I think this Block 
 
 	  | Code: | 	 		  <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|html|xml|class)$">
 
               ExpiresDefault "access plus 1 month"
 
               Header set Cache-Control  "no-cache,proxy-revalidate,must-revalidate,public"
 
            </FilesMatch>  | 	  
 
will work only if the Apache is in the same host where the application server resides. 
 
 
Is it true? Is there a way to match files when the apache proxy is in the remote box?
 
 
Otherwise how can i give Header control for the specific file times in Remote Proxy?
 
 
Thanks in advance for the advices. | 
 
  | 
 
| Back to top | 
 | 
 
 
 
 
 | 
 
 
 |  
 
 |  
  |   
 |