由于80端口需要root用戶才能使用,所以tomcat都是root用戶管理的,為了安全起見昨天安裝了一個nginx作為反向代理,tomcat改為8080端口。但測試發現有幾個接口一直報錯,幾個HTTP頭取不到值,比對其他請求發現是包含了下劃線。在百度和stackoverflow上查找問題發現,要求配置一下nginx,支持HTTP Header name支持下劃線:
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_headers directive.
If the directive is specified on the server level, its value is only used if a server is a default one. The value specified also applies to all virtual servers listening on the same address and port.
但是nginx為什么要加這個配置呢,查找資料有的說HTTP Header name不能包含下劃線。
翻了翻HTTP RFC,好像沒有這個要求。
Each header field consists of a case-insensitive field name followed by a colon (":"), optional leading whitespace, the field value, and optional trailing whitespace.