Permalink
Browse files

* Added microcaching setup for both FCGI and proxy.

  • Loading branch information...
1 parent 29235ea commit 36b60a5bb075e0dc5d44936890b4861edd26a5d7 @perusio committed Oct 23, 2011
@@ -0,0 +1,16 @@
+# -*- mode: nginx; mode: flyspell-prog; ispell-local-dictionary: "american" -*-
+
+### Defining the FastCGI cache zone for the microcache as presented at:
+## http://fennb.com/microcaching-speed-your-app-up-250x-with-no-n.
+
+## If youre using a Nginx version greater than 1.1.1 then you can
+## tweak the Tweaking of the cache loader parameters.
+## Cf. http://forum.nginx.org/read.php?21,213197,213209#msg-213209 for
+## rationale. If you're using a Nginx version lower than 1.1.1 then
+## comment the line below and use the cache zone configuration below this one.
+fastcgi_cache_path /var/cache/nginx/microcache levels=1:2 keys_zone=microcache:5M max_size=1G loader_threshold=2592000000 loader_sleep=1 loader_files=100000;
+
+## If you're not using a Nginx version greater or equal to 1.1.1 then
+## comment the above configuration and use this one. No cache loader
+## tweaking.
+#fastcgi_cache_path /var/cache/nginx/microcache levels=1:2 keys_zone=microcache:5M max_size=1G;
View
@@ -132,6 +132,13 @@ http {
## Include the caching setup. Needed for using Drupal with an external cache.
include map_cache.conf;
+ ## Microcache zone definition for FastCGI.
+ include fastcgi_microcache_zone.conf;
+
+ ## If you're using Apache for handling PHP then comment the line
+ ## above and uncomment the line below.
+ #include proxy_microcache_zone.conf
+
## Include all vhosts.
include /etc/nginx/sites-enabled/*;
}
View
@@ -0,0 +1,16 @@
+# -*- mode: nginx; mode: flyspell-prog; ispell-local-dictionary: "american" -*-
+
+### Defining the proxy cache zone for the microcache as presented at:
+### http://fennb.com/microcaching-speed-your-app-up-250x-with-no-n.
+
+## If youre using a Nginx version greater than 1.1.1 then you can
+## tweak the Tweaking of the cache loader parameters.
+## Cf. http://forum.nginx.org/read.php?21,213197,213209#msg-213209 for
+## rationale. If you're using a Nginx version lower than 1.1.1 then
+## comment the line below and use the cache zone configuration below this one.
+proxy_cache_path /var/cache/nginx/microcache levels=1:2 keys_zone=microcache:5M max_size=1G loader_threshold=2592000000 loader_sleep=1 loader_files=100000;
+
+## If you're not using a Nginx version greater or equal to 1.1.1 then
+## comment the above configuration and use this one. No cache loader
+## tweaking.
+#proxy_cache_path /var/cache/nginx/microcache levels=1:2 keys_zone=microcache:5M max_size=1G;
@@ -144,9 +144,15 @@ location = /index.php {
## This enables a fallback for whenever the 'default' upstream fails.
error_page 502 504 @fallback;
fastcgi_pass phpcgi;
+ ## FastCGI microcache.
+ include sites-available/microcache_fcgi.conf;
+
## To use Apache for serving PHP uncomment the line bellow and
## comment out the above.
#proxy_pass http://phpapache;
+ ## Proxy microcache.
+ #include sites-available/microcache_proxy.conf;
+
## Filefield Upload progress
## http://drupal.org/project/filefield_nginx_progress support
## through the NgninxUploadProgress modules.
@@ -180,9 +180,15 @@ location = /index.php {
## This enables a fallback for whenever the 'default' upstream fails.
error_page 502 504 @fallback;
fastcgi_pass phpcgi;
+ ## FastCGI microcache.
+ include sites-available/microcache_fcgi.conf;
+
## To use Apache for serving PHP uncomment the line bellow and
## comment out the above.
#proxy_pass http://phpapache;
+ ## Proxy microcache.
+ #include sites-available/microcache_proxy.conf;
+
## Filefield Upload progress
## http://drupal.org/project/filefield_nginx_progress support
## through the NgninxUploadProgress modules.
@@ -149,9 +149,15 @@ location = /index.php {
## This enables a fallback for whenever the 'default' upstream fails.
error_page 502 504 @fallback;
fastcgi_pass phpcgi;
+ ## FastCGI microcache.
+ include sites-available/microcache_fcgi.conf;
+
+ ## Proxy microcache.
+ #include sites-available/microcache_proxy.conf;
## To use Apache for serving PHP uncomment the line bellow and
## comment out the above.
#proxy_pass http://phpapache;
+
## Filefield Upload progress
## http://drupal.org/project/filefield_nginx_progress support
## through the NgninxUploadProgress modules.
@@ -179,9 +179,15 @@ location = /index.php {
## This enables a fallback for whenever the 'default' upstream fails.
error_page 502 504 @fallback;
fastcgi_pass phpcgi;
- # To use Apache for serving PHP uncomment the line bellow and
- # comment out the above.
+ ## FastCGI microcache.
+ include sites-available/microcache_fcgi.conf;
+
+ ## To use Apache for serving PHP uncomment the line bellow and
+ ## comment out the above.
#proxy_pass http://phpapache;
+ ## Proxy microcache.
+ #include sites-available/microcache_proxy.conf;
+
# Filefield Upload progress
# http://drupal.org/project/filefield_nginx_progress support
# through the NgninxUploadProgress modules.
@@ -0,0 +1,30 @@
+# -*- mode: nginx; mode: flyspell-prog; ispell-local-dictionary: "american" -*-
+
+### Implementation of the microcache concept as presented here:
+### http://fennb.com/microcaching-speed-your-app-up-250x-with-no-n
+
+## The cache zone referenced.
+fastcgi_cache microcache;
+## The cache key.
+fastcgi_cache_key $host$request_uri;
+
+## For 200 and 301 make the cache valid for 1 second.
+fastcgi_cache_valid 200 301 1s;
+## For 302 make it valid for 1 minute.
+fastcgi_cache_valid 302 1m;
+## For 404 make it valid 1 minute.
+fastcgi_cache_valid 404 1m;
+## If there are any upstream errors or the item has expired use
+## whatever it is available.
+fastcgi_cache_use_stale error timeout invalid_header updating http_500;
+## The Cache-Control and Expires headers should be delivered untouched
+## from the upstream to the client.
+fastcgi_ignore_headers Cache-Control Expires;
+## If we have a cookie we should bypass the cache. The same if we have a
+fastcgi_cache_bypass $no_cache;
+fastcgi_no_cache $no_cache;
+## Add a cache miss/hit status header.
+add_header X-Micro-Cache $upstream_cache_status;
+## To avoid any interaction with the cache control headers we expire
+## everything on this location immediately.
+expires epoch;
@@ -0,0 +1,30 @@
+# -*- mode: nginx; mode: flyspell-prog; ispell-local-dictionary: "american" -*-
+
+### Implementation of the microcache concept as presented here:
+### http://fennb.com/microcaching-speed-your-app-up-250x-with-no-n
+
+## The cache zone referenced.
+proxy_cache microcache;
+## The cache key.
+proxy_cache_key $host$request_uri;
+
+## For 200 and 301 make the cache valid for 1 second.
+proxy_cache_valid 200 301 1s;
+## For 302 make it valid for 1 minute.
+proxy_cache_valid 302 1m;
+## For 404 make it valid 1 minute.
+proxy_cache_valid 404 1m;
+## If there are any upstream errors or the item has expired use
+## whatever it is available.
+proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
+## The Cache-Control and Expires headers should be delivered untouched
+## from the upstream to the client.
+proxy_ignore_headers Cache-Control Expires;
+## If we have a cookie we should bypass the cache. The same if we have a
+proxy_cache_bypass $no_cache;
+proxy_no_cache $no_cache;
+## Add a cache miss/hit status header.
+add_header X-Micro-Cache $upstream_cache_status;
+## To avoid any interaction with the cache control headers we expire
+## everything on this location immediately.
+expires epoch;

0 comments on commit 36b60a5

Please sign in to comment.