roles/nginx: Add fastcgi caching
Bypasses caching for logged in users (right now only for sessions where the "wordpress_logged_in" cookie is set. Doubles the trans- actions per second as measured by siege: $ siege -d1 -t1M -c50 https://mjanja.ch Signed-off-by: Alan Orth <alan.orth@gmail.com>
This commit is contained in:
@ -59,7 +59,29 @@ server {
|
||||
# set script path relative to document root in server block
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
include fastcgi_params;
|
||||
|
||||
fastcgi_cache global;
|
||||
fastcgi_cache_valid any 1h;
|
||||
# Allow use of stale entries if the cache is updating
|
||||
fastcgi_cache_use_stale updating;
|
||||
# Set X-Fastcgi-Cache header to "HIT", "MISS", "BYPASS", etc
|
||||
add_header X-Fastcgi-Cache $upstream_cache_status;
|
||||
# Don't cache when user shift-refreshes (Pragma: no-cache) or when a user is logged in!
|
||||
fastcgi_cache_bypass $http_pragma $logged_in;
|
||||
fastcgi_no_cache $http_pragma $logged_in;
|
||||
}
|
||||
|
||||
include extra-security.conf;
|
||||
}
|
||||
|
||||
# Check if a user is logged in
|
||||
# if so, set $logged_in = 1
|
||||
# otherwise, set $logged_in = 0
|
||||
# See: http://jeradbitner.com/2012/02/nginx-do-not-cache-logged-in-drupal-or-wordpress-users/
|
||||
# See: http://syshero.org/post/50053543196/disable-nginx-cache-based-on-cookies
|
||||
# See nginx bug: http://trac.nginx.org/nginx/ticket/707
|
||||
map $http_cookie $logged_in {
|
||||
default 0;
|
||||
|
||||
~wordpress_logged_in 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user