我正在尝试配置一个 nginx1.12.2反向代理以使用auth_request和proxy_cache验证对微服务的请求。最终用户Bearer随他们的请求发送一个简单的令牌,服务器尝试用它获取资源以确定是否允许他们继续。应该为给定的令牌缓存该资源获取,以减轻身份验证端点的负载。到目前为止,这是我的配置:
ssl_certificate /etc/nginx/ssl/certificate;
ssl_certificate_key /etc/nginx/ssl/key;
proxy_cache_path /var/cache/nginx/auth_cache levels=1:2 keys_zone=auth_cache:1m max_size=1g inactive=60m;
server {
listen 80;
listen 443 ssl;
server_name myapi.mydomain.com;
location / {
proxy_pass http://myapi/;
auth_request /auth;
}
location = /auth {
internal;
proxy_pass https://authendpoint.mydomain.com/api/user/verify;
proxy_cache auth_cache;
proxy_cache_key "$http_x_auth_token$request_uri";
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Run Code Online (Sandbox Code Playgroud)
从客户端的角度来看,这很好用,但是当我查看 nginx 服务器时,没有任何内容写入缓存文件夹。该文件夹已/var/cache/nginx/auth_cache创建,但始终为空。我可能会错过什么?
更新
使用较新的 nginx(1.17.9 …
nginx ×1