nginx simple caching solutions
Mark Alan
varia at e-healthexpert.org
Wed Aug 1 08:44:49 UTC 2012
On Wed, 1 Aug 2012 00:24:12 -0400, "Ian M. Evans"
<ianevans at digitalhit.com> wrote:
> I'm just looking for a way to speed up some dynamic pages that don't
> have personalization and can basically be static for a few minutes.
> Dedicated erver has 2 gig RAM and runs nginx, php-fpm, mysql 5 and a
> qmail server.
>
> Any thoughts or config example links?
1. create dir /var/lib/nginx/fastcgicache and make it readable by nginx
2. at the very begining of your /etc/nginx/sites-available/yoursite
file (i.e., before the first server { ... line) include these 3 lines:
fastcgi_cache_path /var/lib/nginx/fastcgicache levels=1:2
keys_zone=MYCACHE:5m inactive=2h max_size=1g loader_files=1000
loader_threshold=2000;
map $http_cookie $no_cache { default 0; ~SESS 1; }
fastcgi_cache_key "$scheme$request_method$host$request_uri";
3. in the block where you pass the control to php-fpm (i.e., the block
were you put include fastcgi_params; fastcgi_pass ...;
fastcgi_param ...; and so on ) add these:
fastcgi_cache MYCACHE;
fastcgi_keep_conn on;
fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;
fastcgi_cache_valid 200 301 10m;
fastcgi_cache_valid 302 5m;
fastcgi_cache_valid 404 1m;
fastcgi_cache_use_stale error timeout invalid_header updating http_500;
fastcgi_ignore_headers Cache-Control Expires;
expires epoch;
fastcgi_cache_lock on;
Done.
Regards,
M.
More information about the nginx
mailing list