问题现象:
- 前后端分离项目,后端为JAVA,自定义请求头header MY_TOKEN 做鉴权,开发环境前端请求接口,运行正常。
- 部署至服务器,使用nginx做了代理,进行转发。此时奇怪的事情发生了,服务端取不到 自定义header MY_TOKEN 的内容了
分析:
出现异常,无非是因为nginx做转发引起的。推测应该nginx转发没有携带请求头引起的,查找资料发现
句法: | underscores_in_headers |
---|---|
默认: | underscores_in_headers off; |
内容: | http , server |
Enables or disables the use of underscores in client request header fields. When the use of underscores is disabled, request header fields whose names contain underscores are marked as invalid and become subject to the ignore_invalid_headers directive.
意思就是:在客户端请求标头字段中启用或禁用下划线。禁止使用下划线时,名称中包含下划线的请求标头字段将被标记为无效,并受ignore_invalid_headers指令的约束 。
于是乎,在nginx.conf配置文件中增加
underscores_in_headers on;
配置,可以加在keepalive_timeout 65; 下面。
重启nginx服务,使配置生效,再次测试可以取到自定义请求头的内容了。