Created
October 24, 2016 07:41
-
-
Save SumonMSelim/66ed1ccafab75ef231d485f9859c8a16 to your computer and use it in GitHub Desktop.
nginx fastcgi cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### SET THESE OUTSIDE `server` BLOCK ### | |
# set cache path, key and expiration time | |
fastcgi_cache_path /tmp/cache levels=1:2 keys_zone=MYAPP:512m inactive=60m; | |
# handle nginx crash, timeout, error responses and serve cached data | |
fastcgi_cache_use_stale error timeout invalid_header http_500; | |
# ignore cache headers | |
fastcgi_ignore_headers Cache-Control Expires Set-Cookie; | |
### SET THESE INSIDE `server` BLOCK ### | |
# set cache | |
set $no_cache 0; | |
# disable caching for requests other than GET | |
if ($request_method != GET) { | |
set $no_cache 1; # disable caching | |
} | |
# set cache key | |
fastcgi_cache_key "$scheme$request_method$host$uri"; | |
### SET THESE INSIDE `location ~ \.php$` BLOCK ### | |
fastcgi_cache MYAPP; | |
fastcgi_cache_bypass $no_cache; | |
fastcgi_no_cache $no_cache; | |
fastcgi_cache_valid 200 5m; # cache validation time | |
add_header X-Fastcgi-Cache $upstream_cache_status; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment