Skip to content

Instantly share code, notes, and snippets.

@ansulev
Last active February 26, 2020 01:26
Show Gist options
  • Save ansulev/4b164f27f9bb10372d29a29c0d1c37a8 to your computer and use it in GitHub Desktop.
Save ansulev/4b164f27f9bb10372d29a29c0d1c37a8 to your computer and use it in GitHub Desktop.
Micro caching for Nginx
TODO: Compare with: https://www.howtoforge.com/why-you-should-always-use-nginx-with-microcaching
mkdir /usr/share/nginx/cache
#mkdir /var/run/nginx/cache
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_cache microcache;
fastcgi_cache_key $scheme$host$request_uri$request_method;
fastcgi_cache_valid 200 301 302 30s;
fastcgi_cache_use_stale updating error timeout invalid_header http_500;
fastcgi_pass_header Set-Cookie;
fastcgi_pass_header Cookie;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
/etc/nginx/nginx.conf
fastcgi_cache_path /usr/share/nginx/cache/fcgi levels=1:2 keys_zone=microcache:10m max_size=1024m inactive=1h;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment