1) 自定义请求头获取不到
请求头request_token中包含'_'字符,会nginx过滤掉。默认情况下,underscores_in_headers为off,表示当客户端请求头中带有下划线的字段默认将会被标识为无效字段。
解决方案
添加如下配置:
http {
underscores_in_headers on;
}
2)nginx没有透传host请求头,tomcat 400
nginx
默认情况下nginx反向代理是不会转发请求中的Host头部,nginx在没有配置proxy_set_header HOST $host 的时候,在转发http请求的时候会默认把upstream的名称作为Host头部的内容。如果upstream的名称的是非法,就会导致tomcat响应400。例如名称中出现 _ 就是不规范的。
tomcat 更新日志:
Enable strict validation of the provided host name and port for all connectors. Requests with invalid host names and/or ports will be rejected with a 400 response. (markt)
Implement the requirements of RFC 7230 (and RFC 2616) that HTTP/1.1 requests must include a Host header and any request that does not must be rejected with a 400 response. (markt)
Implement the requirements of RFC 7230 that any HTTP/1.1 request that specifies a host in the request line, must specify the same host in the Host header and that any such request that does not, must be rejected with a 400 response. This check is optional and disabled by default. It may be enabled with the allowHostHeaderMismatch attribute of the Connector. (markt)
Implement the requirements of RFC 7230 that any HTTP/1.1 request that contains multiple Host headers is rejected with a 400 response. (markt)
Implement configuration options to work-around specification non-compliant user agents (including all the major browsers) that do not correctly %nn encode URI paths and query strings as required by RFC 7230 and RFC 3986. (markt)
解决方案
location /test {
proxy_set_header Host $host;
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}