如何在nginx上公开自定义标头

3
我们的https请求发送新的头部“X-XSRF-TOKEN”到Nginx。有时该头部会传递“= null”到我的后端服务器。
我的问题是,有没有选项可以在我的access.log中看到这个头部?
我该如何确保Nginx没有阻止该头部?
我必须说98%的请求它们都带有正确的值。
谢谢!

太棒了!它正常运行了!谢谢你。 - undefined
1个回答

7
当然,您可以定义任何自定义访问日志格式并使用任何可用的nginx 内部变量。默认的nginx日志格式为:
log_format  combined  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

只需定义一个新的访问日志格式,并在其中添加$http_x_xsrf_token变量:

log_format  debug     '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" "$http_x_xsrf_token"';
access_log  /var/log/nginx/access_log  debug;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接