遇到一个比较奇怪的问题,发现经过Nginx反向代理到服务器端时部分头字段被过滤掉了。经过查阅资料,得知HTTP头字段名称在标准下是使用中划线拼接的,例如
Custom-Header: QTTC
假如你想使用下划线拼接
Custom_Header: QTTC
这是不符合HTTP标准的,默认在Nginx下进行会被drop掉,担心跟CGI变量混淆,以下是官方说明
missing-disappearing-http-headers
If you do not explicitly set underscores_in_headers on;, NGINX will silently drop HTTP headers with underscores (which are perfectly valid according to the HTTP standard). This is done in order to prevent ambiguities when mapping headers to CGI variables as both dashes and underscores are mapped to underscores during that process.
所以如果需要使用下划线拼接的头字段,就需要明确声明underscores_in_headers
在配置文件里
nginx.conf
...
server {
...
underscores_in_headers on;
...
}
然后重启一下Nginx即可生效。