Personal tools
You are here: Home Storage Caching static files for Zope / Plone in Nginx

Caching static files for Zope / Plone in Nginx

Posted by Rafal Zawadzki at Jul 01, 2010 09:45 PM |

short info how to configure Nginx to cache static file served by Zope

Zope / Plone usually sets proper headers for static files, which prevents browsers from pointless downloading same files again and again. But for every new user at least one hit direct to Zope still has to be made.

Latests versions of Nginx offer quite good and well configurable reverse caching feature. For example, if we want to cache css and javascript files, we have to modify config files in two places, first in http section (usually /etc/nginx/nginx.conf):

proxy_cache_path  /data/nginx/cache  levels=1:2 keys_zone=one:10m inactive=7d  max_size=200m;
proxy_temp_path /data/nginx/temp;

we set cache storage with maximum size 200 megabytes, valid for 7 days. And in the server directive of virtual's host configuration file, (before Virtual Host Monster proxy directive):

 

location ~* \.(css|js)$ {
  rewrite ^(.*)$ /VirtualHostBase/http/$http_host:80/site/VirtualHostRoot$1 break;  
  proxy_pass   http://127.0.0.1:8080;
  proxy_set_header  X-Real-IP  $remote_addr;
  proxy_cache             one;
  proxy_cache_key         static_service$request_uri; 
  proxy_cache_valid       200  1h; 
  proxy_cache_use_stale   error timeout invalid_header;

}

 

With this configuration we have configured cache storage and we set also turn on caching of css and  js responses (with status 200) for 1 hour. What is important, location with files which to cache should be define before main location / (Virtual Host Monster). More informations on Nginx's wiki page: http://wiki.nginx.org/NginxHttpProxyModule

Comments (0)