We have found a solution to this question.
The correct method of doing this is to construct a cache key by using nginx $arg_...
variables. $arg_...
will contain query string parameters. So in the above example we would use $arg_parameter
and $arg_parameter2
within the cache key.
The result in the nginx.conf
looks like:
http {
...
server {
location / {
...
proxy_cache_key $scheme$proxy_host$uri$is_args$arg_parameter$arg_parameter2;
}
}
...
}
Note that querystring parameter containing an hyphen (dash), such as data-*
parameters, do not work with the $arg_paramName
syntax. A workaround using Lua can be found in this post.
You could use proxy_cache_bypass
.
proxy_cache_bypass $http_cache_control;
This will cause nginx to fetch a fresh copy of the document in the presence of the Cache-Control
header in the HTTP request from the client.
Note that the resulting response from the backend is still eligible for caching. If you want to disqualify it from being cached, use the same arguments with the proxy_no_cache
directive, too.
Source: http://wiki.nginx.org/HttpProxyModule#proxy_cache_bypass
If you specifically want to only bypass the cache when the client has Cache-Control: max-age=0
in the headers (e.g. to explicitly not support another variant, Cache-Control: no-cache
, which is actually supposedly a stronger preference for a fresh copy of the page than max-age=0
is), then you can use the following, which I won't recommend due to such limitation:
set $cc_ma 0;
if ($http_cache_control = "max-age=0") { # honour ⌘R, ignore ⇧⌘R (yes, bad idea!)
set $cc_ma 1;
}
proxy_cache_bypass $cc_ma;
BTW, there's also Pragma: no-cache
, which this obviously won't account for, although in my limited set of experiments, it's always accompanied by a Cache-Control: no-cache
, so, the original one-liner would probably do the best job.
As a note, SeaMonkey sends Cache-Control: max-age=0
when you click Reload or ⌘R, and Pragma: no-cache\r\nCache-Control: no-cache
when you Shift Reload or ⇧⌘R.
Best Answer
You can specifically instruct nginx to ignore headers with:
With these directives, an nginx proxy instance will ignore the headers sent by the upstream server and set its own headers for the client (depending on what you specify in the proxy response configuration).