Question

When I use SSI, NGinx uses the wrong cache key for the subrequest

fastcgi_cache_key       "$request_method $scheme://$host$uri";

The problem is, that it ends up in an infinite recursion, because on the main request NGinx stores the page including the SSI-element in its cache and then when it triggers the subrequest, uses this page (including the SSI-element) as result of the subrequest (and so on and so on). I thought $uri is exactly designed to avoid this (unlike $request_uri), but obviously it doesn't work.

nginx version is 1.3.8

Was it helpful?

Solution

A slightly longer debug-session (the nginxs debug-logs are ... big) gave me the answer: It was not the cache-key directly, but by default the REQUEST_URI is set to $request_uri in /etc/nginx/fastcgi_params. The cache key is correct, but the request is always identical to the parents one, so the parent page is cached twice: Once for the parent-uri-key and once for the ssi-subrequest. On every subsequent call the (broken) cached values is used.

fastcgi_param REQUEST_URI $uri;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top