Caching with nginx
Example configuration file
Browser caching
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg)$ {
expires 7d;
}location ~* \.(pdf)$ {
expires 7d;
}
Fastcgi caching
fastcgi_cache_path /usr/local/nginx/cache levels=1:2 keys_zone=WORDPRESS:100m inactive=10m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
add_header X-Cache $upstream_cache_status;
nginx documentation explains
fastcgi_cache_path
A directory in which to place the cached responses and a shared memory zone (keys_zone = name:size) to store active keys and response metadata.
levels
Colon-separated length of subdirectory name at each level (one or two), maximum of three levels deep
#Cache everything by default
set $no_cache 0;
if ($request_method = POST) { set $no_cache 1; } # 1
if ($query_string != "") { set $no_cache 1; } # 2
if ($request_uri ~* "/(wp-admin/|wp-login)") { set $no_cache 1; } # 3
if ($http_cookie = "PHPSESSID") { set $no_cache 1; } # 4
# 1. Don't cache POST requests
# 2. Don't cache if the URL contains a query string
# 3. Don't cache these URLs
# 4. Don't cache if there is a cookie called PHPSESSID