【问题标题】:how to expose custom header on nginx如何在 nginx 上公开自定义标头
【发布时间】:2020-11-03 09:57:06
【问题描述】:

我们的 https 请求向 Nginx 发送新的标头“X-XSRF-TOKEN”。 有时标头会“= null”到我的后端服务器。

我的问题,是否有任何选项可以在我的 access.log 中查看此标头?

如何确保 Nginx 没有阻塞标头。

我不得不说请求中的 98%,它们的价值是正确的。

谢谢!

【问题讨论】:

  • 它正在工作!谢谢。

标签: nginx http-headers


【解决方案1】:

当然,您可以定义任何自定义访问日志格式并使用任何可用的 nginx internal variables。默认的 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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-19
    • 1970-01-01
    • 2015-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-29
    • 2022-12-15
    相关资源
    最近更新 更多