我想缓存请求标头字段授权中的令牌。
Authorization : Bearer abcdefghijklmnopqrstuvwxyz
我的目标是,我不必验证验证服务器上的每个请求。如果授权令牌已缓存(且有效),则请求应调用 API 而无需验证。
location /main {
auth_request /auth;
proxy_ignore_headers Cache-Control;
proxy_pass http://API;
proxy_http_version 1.1;
}
location /auth {
internal;
proxy_cache my_cache;
proxy_ignore_headers Cache-Control;
proxy_cache_key "$http_authorization";
proxy_pass https://validationserver;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
}
这是我的设置,但这不起作用。
我希望你可以帮助我。
问候!
您想要完成哪种身份验证?它是一种站点范围的身份验证机制,其中每个经过身份验证的用户都对内容具有相同的权限吗?或者更微妙的是,给定用户可能有权也可能无权访问某些资源?
因为如果是后者,那么您实际上就让您的应用程序面临安全漏洞——任何经过身份验证的用户都可以使用其身份验证令牌来执行他们可能有权或可能无权执行的操作,就像任何用户名一样或者,如果在经过验证和缓存的原始授权请求中出现正确的用户名/ID 时,首先缓存令牌,则作为查询中的参数传递的 ID 将受到完全信任。
或者,请注意,在 nginx 1.7.3 之前不支持缓存,根据http://nginx.org/r/auth_request http://nginx.org/r/auth_request.
另请注意,默认情况下,请求或响应中存在 cookie 同样会阻止内容被缓存http://nginx.org/r/proxy_cache http://nginx.org/r/proxy_cache。按照http://serverfault.com/questions/462799/leverage-proxy-caching-with-nginx-by-removing-set-cookie-header/467774#467774 http://serverfault.com/questions/462799/leverage-proxy-caching-with-nginx-by-removing-set-cookie-header/467774#467774,因此可能需要以下内容才能使缓存发挥作用:
proxy_hide_header Set-Cookie;
proxy_ignore_headers Set-Cookie;
# important! Remember the special inheritance rules for proxy_set_header:
# http://nginx.org/ru/docs/http/ngx_http_proxy_module.html#proxy_set_header
proxy_set_header Cookie "";
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)