nginx - 在 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
字段,因此我希望在访问日志中会出现该值,但只是-
出现,表明该值不存在。在代理的服务器中,我可以访问 header 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"';
$remote_user
用你的$user
变量替换
推荐阅读
- c# - 如何在 c# 中使用 localhost 作为重定向 URI 和 OAuth 隐式授权来获取 access_token?
- unit-testing - 开玩笑找不到文件导入
- error-handling - 使用 psftp 无法忽略错误
- javascript - 如何使用最接近和父母的javascript方法来获取角度6中的td值
- batch-file - 从 csv 创建用户的批处理脚本
- javascript - 以角度使用 JSON 对象的嵌套数组
- c# - (Wix 安装程序)如何包含自定义操作依赖项
- javascript - jquery load -> 不加载特定的 php 文件,而是加载网页 2 次(yii2)
- mysql - 选择行 mysql order by custom value 从表格底部到表格顶部
- python - 是否可以将两个数据帧发送到我的 html(烧瓶)?