logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

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.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Mod_Cache & Mod_Disk_Cache Validation
Author
tholian



Joined: 22 Apr 2015
Posts: 4
Location: Malaysia

PostPosted: Mon 25 Jul '16 12:23    Post subject: Mod_Cache & Mod_Disk_Cache Validation Reply with quote

Dear All,

My current setup is as following:

User <---> Apache <---> Tomcat

Apache is doing reverse proxy to the tomcat server to serve the site.

I have a request to cache the static files from the tomcat server on the apache files so that after the initial cache, subsequent user requests should hit the cache instead of the tomcat server.

I have the following configuration and files / folders are being generated in the defined cache folder when i access the files hosted in the Tomcat from Apache.

initial request of the files, shows the code 200, if i reload, it shows 304. Not sure if this is because the files are cached in the browser. How can I ensure the static files are being served from the Apache?

Your kind help will be much appreciated

Code:


<IfModule mod_headers.c>
   Header unset X-Powered-By
   Header unset ETag
   Header unset Content-Security-Policy
   Header unset Server
   Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
   Header always append X-Frame-Options SAMEORIGIN
   Header set X-XSS-Protection: "1; mode=block"
   Header set X-Content-Security-Policy "allow 'self';"
   Header set X-Permitted-Cross-Domain-Policies "none"
   Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure

    # Serve gzip compressed CSS files if they exist
    # and the client accepts gzip.
    RewriteCond "%{HTTP:Accept-encoding}" "gzip"
    RewriteCond "%{REQUEST_FILENAME}\.gz" -s
    RewriteRule "^(.*)\.css" "$1\.css\.gz" [QSA]

    # Serve gzip compressed JS files if they exist
    # and the client accepts gzip.
    RewriteCond "%{HTTP:Accept-encoding}" "gzip"
    RewriteCond "%{REQUEST_FILENAME}\.gz" -s
    RewriteRule "^(.*)\.js" "$1\.js\.gz" [QSA]


    # Serve correct content types, and prevent mod_deflate double gzip.
    RewriteRule "\.css\.gz$" "-" [T=text/css,E=no-gzip:1]
    RewriteRule "\.js\.gz$" "-" [T=text/javascript,E=no-gzip:1]


    <FilesMatch "(\.js\.gz|\.css\.gz)$">
      # Serve correct encoding type.
      Header append Content-Encoding gzip

      # Force proxies to cache gzipped &
      # non-gzipped css/js files separately.
      Header append Vary Accept-Encoding
    </FilesMatch>
</IfModule>

<IfModule mod_deflate.c>
   AddOutputFilterByType DEFLATE application/javascript
   AddOutputFilterByType DEFLATE application/rss+xml
   AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
   AddOutputFilterByType DEFLATE application/x-font
   AddOutputFilterByType DEFLATE application/x-font-opentype
   AddOutputFilterByType DEFLATE application/x-font-otf
   AddOutputFilterByType DEFLATE application/x-font-truetype
   AddOutputFilterByType DEFLATE application/x-font-ttf
   AddOutputFilterByType DEFLATE application/x-javascript
   AddOutputFilterByType DEFLATE application/xhtml+xml
   AddOutputFilterByType DEFLATE application/xml
   AddOutputFilterByType DEFLATE font/opentype
   AddOutputFilterByType DEFLATE font/otf
   AddOutputFilterByType DEFLATE font/ttf
   AddOutputFilterByType DEFLATE image/svg+xml
   AddOutputFilterByType DEFLATE image/x-icon
   AddOutputFilterByType DEFLATE text/css
   AddOutputFilterByType DEFLATE text/html
   AddOutputFilterByType DEFLATE text/javascript
   AddOutputFilterByType DEFLATE text/plain
   AddOutputFilterByType DEFLATE text/xml

   # Remove browser bugs (only needed for really old browsers)
   BrowserMatch ^Mozilla/4 gzip-only-text/html
   BrowserMatch ^Mozilla/4\.0[678] no-gzip
   BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
   Header append Vary User-Agent
</IfModule>

<IfModule mod_expires.c>
   ExpiresActive On
   ExpiresByType image/jpg "access plus 1 year"
   ExpiresByType image/jpeg "access plus 1 year"
   ExpiresByType image/gif "access plus 1 year"
   ExpiresByType image/png "access plus 1 year"
   ExpiresByType text/css "access plus 1 month"
   ExpiresByType application/pdf "access plus 1 month"
   ExpiresByType text/x-javascript "access plus 1 month"
   ExpiresByType application/javascript "access plus 1 month"
   ExpiresByType application/x-shockwave-flash "access plus 1 month"
   ExpiresByType image/x-icon "access plus 1 year"
   ExpiresDefault "access plus 2 days"
</IfModule>


<IfModule cache_module>

   <IfModule cache_disk_module>
       
       CacheRoot C:/Apache/cache
       CacheEnable disk /
      CacheDirLevels 2
        CacheDirLength 3
      CacheIgnoreNoLastMod On
      CacheIgnoreCacheControl On
      CacheIgnoreQueryString Off
      CacheDefaultExpire 3600
      CacheMaxExpire 86400
      CacheMaxFileSize 5000000
    </IfModule>
</IfModule>




Thank you.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7355
Location: Germany, Next to Hamburg

PostPosted: Mon 01 Aug '16 15:43    Post subject: Reply with quote

the 304 aka Not Modified. The server tells the browser that the browser has the last version and doesn't need to load it again.

How can you ensure that apache is serving the file and not tomcat?
Compare the log files.
Back to top


Reply to topic   Topic: Mod_Cache & Mod_Disk_Cache Validation View previous topic :: View next topic
Post new topic   Forum Index -> Apache