Can nginx cache on user-defined headers?

I'd assume adding $http_foo and $http_bar to your proxy_cache_key should do the trick


nginx has configuration directive proxy_cache_key, which can be used to define cache key.

By default the cache key is $scheme$proxy_host$request_uri. By adding $http_foo to the key you'll get separate caching for different headers.

There is a corresponding directive for fastcgi too.