How i can setup a nginx cache strategy that first try amazon s3, then memcache and do a fallback on miss?

Posted by Tim on Server Fault See other posts from Server Fault or by Tim
Published on 2013-11-11T15:12:03Z Indexed on 2013/11/11 15:57 UTC
Read the original article Hit count: 151

Filed under:
|
|

i have a large site with lot of pages that almost never change, right now i am using two memcache servers (amazon elasticache), but this its really expensive.

Thats why for this files that barely never change i want to upload them to amazon s3 and shutdown 1 memcache server.

Here is my conf;

location ~ /longterm/(.*){
   proxy_pass http://amazonS3bucket;
   proxy_intercept_errors on;
   proxy_next_upstream http_404;
   error_page 404 503 = @fallback_memcached
}

location @fallback_memcache {
   set $memcached_key $uri;
   memcached_pass     name:11211;
   error_page         404 @fallback;
}

location @fallback {
   try_files $uri $uri/index.html
}

I dont know why but the config doesnt work on the final fallback; if i got an amazon S3 hit it works, if i got an amazon S3 miss and a memcache hit it works, but if i got an amazon S3 miss then a memcache miss when it try to resolve the las fallback it fails.

I am also thinking in use the amazon s3 fuse http://code.google.com/p/s3fs/ instead of the proxy pass i think it would be easier for implement, i would also be less performant?

© Server Fault or respective owner

Related posts about nginx

Related posts about amazon-s3