Nginx forwarding custom header loss and access.log print header parameters

version

nginx version: nginx/1.19.6

Question 1

Nginx forwarding error report/nginx forwarding loses header header information

# 自定义请求头
my_token 123456789

http {
    
    
    # 配置 nderscores_in_headers=on ,默认false
    underscores_in_headers on;
    }

note

When underscores_in_headers is not configured or is off #-It
is supported, but you need to configure _ to receive
# $http_my_token1 to receive the following custom request header
my-token1 token1

Configure 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;
}

Question 2

Configure custom parameters,
assuming the custom header is

XK-Autho 12345678

Print custom parameter configuration

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

in conclusion

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

Guess you like

Origin blog.csdn.net/kq1983/article/details/113182842