Skip to content

Instantly share code, notes, and snippets.

@sergejmueller
Last active August 29, 2015 14:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sergejmueller/0a3d98b3fc1df57e2e69 to your computer and use it in GitHub Desktop.
Save sergejmueller/0a3d98b3fc1df57e2e69 to your computer and use it in GitHub Desktop.
Nginx-Caching für PHP-generierte Inhalte. Weitere Details: http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html
## DEFAULT
set $no_cache 0;
## RULES
if ( $request_uri ~ "/wp-" ) {
set $no_cache 1;
}
if ( $http_cookie ~ (wp-postpass|wordpress_logged_in|comment_author)_ ) {
set $no_cache 1;
}
## INIT
fastcgi_cache microcache;
fastcgi_cache_use_stale updating;
#fastcgi_hide_header "Set-Cookie";
fastcgi_cache_valid any 30m;
fastcgi_no_cache $no_cache;
fastcgi_cache_bypass $no_cache;
## HEADER
add_header X-Cache $upstream_cache_status;
http {
## ... ##
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:5m max_size=5m inactive=1h;
fastcgi_cache_key "$request_method|$http_if_modified_since|$http_if_none_match|$host|$request_uri";
## ... ##
}
server {
## ... ##
location ~ \.php$ {
## ... ##
include /etc/nginx/conf.d/fastcgi_cache;
## ... ##
}
## ... ##
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment