Skip to content

How to setup fcgi cache in nginx

Taymindis Woon edited this page Jul 23, 2018 · 2 revisions
http {
  ....
  fastcgi_cache_path /var/cache/nginxfastcgi levels=1:2 keys_zone=fastcgicache:10m inactive=10m max_size=64m;
  fastcgi_cache_key $scheme$request_method$host$request_uri;
  # note: can also use HTTP headers to form the cache key, e.g.
  #fastcgi_cache_key $scheme$request_method$host$request_uri$http_x_custom_header;
  fastcgi_cache_lock on;
  fastcgi_cache_use_stale error timeout invalid_header updating http_500;
  fastcgi_cache_valid 5m;
  fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
  ...
  #[[ Fcgi function Apps ]]  
location /my_service_path/getQuotation {
         add_header Allow "GET, POST, HEAD" always;
          if ( $request_method !~ ^(GET)$ ) {
             return 405;
           }
            add_header X-Cache $upstream_cache_status;
            fastcgi_cache fastcgicache;
            # fastcgi_cache_bypass $fastcgi_skipcache;
            # fastcgi_no_cache $fastcgi_skipcache;
         
            include /etc/nginx/fastcgi_params;
            fastcgi_param FN_HANDLER getQuotation;
            fastcgi_pass 127.0.0.1:2005;
}
...