nginx access_token丢失问题
一、问题描述
前端请求经过nginx转发到后端服务发现部分header丢失,比如
access_token
tcpdump -nn -i ens3 host backendIp -w output1.pcap
tcpdump -nn -i ens3 src host clientIp -w output2.pcap
二、解决办法
方案1. 改用短横线或驼峰风格
access_token
=>access-token
或access_token
=>accessToken
方案2. 调整nginx配置
Syntax:underscores_in_headers on | off;
Default:underscores_in_headers off;
Context: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 header directive.
http请求header中带有下划线不向后端转发,必须添加underscores_in_headers on; 参数到 default server中