0
点赞
收藏
分享

微信扫一扫

nginx转发自定义header丢失及access.log打印header参数

闲嫌咸贤 2022-02-15 阅读 82


版本


nginx version: nginx/1.19.6


问题1

nginx转发报错问题/nginx转发丢失header头部信息

# 自定义请求头
my_token 123456789
http {
# 配置 nderscores_in_headers=on ,默认false
underscores_in_headers on;
}

注意


underscores_in_headers不配置或者是off的时候
# -是支持的,不过要配置_来接收
# $http_my_token1 来接收下面的自定义请求头
my-token1 token1


配置access.log

http {
include mime.types;
underscores_in_headers on;

log_format access_main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'
'$http_requestPlatform $http_saleType "$http_XK_Autho" $http_my_token';

access_log logs/access.log access_main;
}

问题2

配置自定义参数

假设自定义头是

XK-Autho 12345678

打印自定义参数配置

原始请求头         XK-Autho
打印header日志配置   $http_XK_Autho
原始请求头前面要加个$http,把-替换成_
XK_Autho 变成 $http_XK_Autho

结论

自定义请求头,不管是-还是_
> 最终打印access.log,都要配置以$http开头,并把-替换成_
> 比如$http_my_header
> 如果自定义请求头本身有下划线_的,则要配置 underscores_in_headers on;
> 如果自定义请求头本身是横杠的-,则可以不用配置underscores_in_headers



举报

相关推荐

0 条评论