在Nginx的访问日志中显示从auth_request检索到的远程用户
·
问题:在Nginx的访问日志中显示从auth_request检索到的远程用户
我在 nginx 中有以下配置:
location /api/ {
auth_request /auth/request/;
auth_request_set $user $upstream_http_remote_user;
proxy_set_header Remote-User $user;
proxy_pass http://...;
}
我正在设置Remote-User字段,所以我希望在访问日志中会出现该值,但只有-出现,表明该值不存在。在代理的服务器中,我可以访问标头Remote-User,所以我知道该值设置得很好,但无法在访问日志中显示它。
我想访问日志可能是在身份验证请求之前生成的。
有没有办法通过这种配置在访问日志中获取Remote-User?
解答
在你的 nginx.conf 你应该有类似的东西
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user _agent" "$http_x_forwarded_for"';
用您的$user变量替换$remote_user
更多推荐

所有评论(0)