Nginx caching - bring on the traffic on [2013-01-05 Sat 17:46]

Just like everyone who runs a blog, there's the remote risk of an influx of traffic bringing down the site. This blog engine is pretty quick, but my xen box probably would get crushed under load.

I set up nginx to do caching for all non-authenticated users. It will also return the cached version just in case I am restarting the picolisp process or in case it goes down.

proxy_cache_path  /tmp/cache levels=1:2 keys_zone=my-test-cache:8m max_size=5000m inactive=300m;
server{
        listen 80 ; #or change this to your public IP address eg
        server_name csilo.com www.csilo.com;
        access_log /var/log/csilo.access_log;
        error_log /var/log/csilo.error_log;

  set $logged_in 0;
  if ($http_cookie ~ "Session=(.+)") {
    set $logged_in 1;
    break;
  }
  location / {
    proxy_pass http://127.0.0.1:21000/;
    proxy_pass_header Set-Cookie;
    proxy_no_cache $logged_in;
    proxy_cache my-test-cache;
    proxy_cache_key "$host$request_uri$logged_in";
    proxy_cache_valid  200 302  1m;
    proxy_cache_use_stale   error timeout invalid_header updating;
  }
}



Prev: Add/Edit posts  Next: Unit testing in picolisp