How to cache image urls with query strings?

jeanpaul nginx-forum at
Sun Feb 26 10:12:53 UTC 2017


The proxy_cache_key uses request parameters by default. As stated in it
uses $scheme$proxy_host$request_uri by default. 

The $request_uti do contain the request parameters:

full original request URI (with arguments)

So a way to deal with this is using a self-made cache_key and strip the
arguments with a regex:

set $cacheuri $request_uri;
if ($cacheuri ~ /example/images/([^\?]*)) {
     set $cacheuri /example/images/$1;
proxy_cache_key $cacheuri;

Note: the regex is untested, but just to give you an idea.


Posted at Nginx Forum:,272608,272623#msg-272623

More information about the nginx mailing list