help about how proxy_cache to store differet cache file by httpheader vary Accept-Encoding like squid

Ryan Malayter malayter at
Fri Mar 12 08:09:41 MSK 2010

2010/3/5 杨春宇 <yangchunyu at>:
> I think use proxy_cache_key to define caching key is good idea .
> but I do not know which variable to use that can distinguish client side
> support compressed or compressed content and store the different cache file.

Here's an example I've used. Of course the upstream server must return
compressed responses to HTTP/1.0 requests, which many do not by
#normalize all accept-encoding headers to just gzip or the empty string
	set $myae "";
	if ($http_accept_encoding ~* gzip) {
		set $myae "gzip";
#the following prevents comressed responses from backend
	proxy_set_header Accept-Encoding $myae;
	proxy_pass http://backend;
#the following uses a combination of URI and the accept-encoding as a
proxy cache key
	proxy_cache_key "$host$request_uri$myae";

More information about the nginx mailing list