Caching auth_request!

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


Hello,

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
max_size=2m
                 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 http://127.0.0.1:6001;
            proxy_pass http://auth_server;
        }

I can see that my requests are being cached
when I do:  curl  https://10.0.2.6:443/devices 
however, caching is useless because the auth server is requested every
time.

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

Has anyone experienced the same issue?

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,291390,291390#msg-291390



More information about the nginx mailing list