iamhuzl

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  1 随笔 :: 13 文章 :: 21 评论 :: 0 Trackbacks
    由于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:httpserver

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,好像没有这个要求。

3.2 Header Fields


Each header field consists of a case-insensitive field name followed by a colon (":"), optional leading whitespace, the field value, and optional trailing whitespace.

  header-field   = field-name ":" OWS field-value OWS    
field-name = token

token
的范思科表达式定义:
token = 1*tchar
tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA ; any VCHAR, except delimiters
Delimiters are chosen from the set of US-ASCII visual characters not allowed in a token (DQUOTE and "(),/:;<=>?@[\]{}").

如果没理解错的话,HTTP header name应该可以包含下划线的。
还是下划线在nginx里有特殊用途,好像有的说是cgi会用到。
posted on 2014-07-10 12:37 温水青蛙 阅读(2020) 评论(1)  编辑  收藏

评论

# re: nginx处理HTTP header问题 2016-05-27 19:53 sAka
感谢您的经验,万分感谢。  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: