Caching auth_request!

bouvierh nginx-forum at
Thu Apr 29 18:50:06 UTC 2021


I am caching the result of auth_request. This is the simplified code:
       proxy_cache_path /var/cache/nginx levels=1 keys_zone=token_cache:1m
                 inactive=60m use_temp_path=off;

        location /devices {
            auth_request /auth;
            auth_request_set $token $upstream_http_x_token;
            proxy_set_header    Authorization $token;
            set $endpoint https://upstream;
            proxy_pass $endpoint;


        location = /auth {
            proxy_cache token_cache;
            proxy_cache_valid any 30m;
            proxy_cache_key   "$request_uri";
            set $endpoint;
            proxy_pass http://auth_server;

I can see that my requests are being cached
when I do:  curl 
however, caching is useless because the auth server is requested every

What is really strange is that when I curl the auth server directly, it
behaves as expected:
Then the auth_server is hit only after the cache expires

Has anyone experienced the same issue?

Posted at Nginx Forum:,291390,291390#msg-291390

More information about the nginx mailing list