8

Is it possible to configure nginx proxy_cache_key to include a specific header as a key instead of just request/args?

I would like to cache my API GET hits and am using x-authtoken in my headers for authentication. This is ignored currently, so another user will get the cache of a previous user if I leave cache enabled.

2

1 Answer 1

12

@Alexy Ten posted the link to the correct location in the docs, but just to make it easier for people in the future:

$http_name arbitrary request header field; the last part of a variable name is the field name converted to lower case with dashes replaced by underscores

So in your case it would look like: proxy_cache_key $http_x_authtoken.

2
  • 2
    Thanks for this, just be sure to convert dashes to underscores as the docs say. I was able to cache AJAX requests using the $http_x_requested_with header. My full cache key looks like this: fastcgi_cache_key $scheme$request_method$host$request_uri$http_x_requested_with;
    – andyvanee
    Jan 18, 2017 at 18:05
  • Thanks @PhilippClaßen!
    – ccnokes
    Jan 20, 2021 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.