2

I have tested proxy_cache_key with a single $scheme

 proxy_cache_key $scheme;
 proxy_pass http://127.0.0.1:8081/;

Then I request one to cache.

curl http://127.0.0.1:8080/a.html

Then I requested again to confirm the cache

curl http://127.0.0.1:8080/a.html

No problem

Then I request other url

curl http://127.0.0.1:8080/b.html

And hope that it hits cache because the key is $scheme

but it gave me the content of b.html

Why proxy_cache_key $scheme; does not work?

1 Answer 1

1

The headers from the proxied server response can change the "final" cache key.

From https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ignore_headers :

If not disabled, processing of these header fields has the following effect:

  • “X-Accel-Expires”, “Expires”, “Cache-Control”, “Set-Cookie”, and “Vary” set the parameters of response caching;

You can check if those headers are included in the response and/or try ignoring them.

1
  • 1
    I was messing with cookies, and I had a hard time understanding why nginx was still taking into account request "Cookie" (even after ''proxy_set_header Cookie "''). "proxy_ignore_headers Vary" fixed it! Sep 21, 2020 at 11:02

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.