nginx支持带下划线的header实现
nginx对header 的名字字符做了限制,默认 underscores_in_headers 为off,表示如果header name中包含下划线,则忽略掉,后端服务就获取不到该请求头。

为了支持header带下划线的参数,可以在http内或者server内设置如下参数:
underscores_in_headers on;//默认是off
如nginx的配置如下:
http {
log_format main '$http_app_id';
access_log /var/log/nginx/access.log main;
........
}带上自定义header【app_id】去请求nginx

打印的日志如下,无法获取值:

配置文件中加上【underscores_in_headers on;】
http {
log_format main '$http_app_id';
access_log /var/log/nginx/access.log main;
underscores_in_headers on;
........
}再次带上自定义header【app_id】去请求nginx,日志找那个就可以打印出自定义header【app_id】的值了

到此这篇关于nginx支持带下划线的header实现的文章就介绍到这了,更多相关nginx 带下划线header内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
Nginx结合Openresty通过Lua+Redis实现动态封禁IP
为了封禁某些爬虫或者恶意用户对服务器的请求,我们需要建立一个动态的 IP 黑名单,本文主要介绍了Nginx结合Openresty通过Lua+Redis实现动态封禁IP,感兴趣的可以了解一下2023-11-11


最新评论