nginx处理HTTP header问题

由于80端口需要root用户才能使用,所以tomcat都是root用户管理的,为了安全起见昨天安装了一个nginx作为反向代理,tomcat改为8080端口。但测试发现有几个接口一直报错,几个HTTP头取不到值,比对其他请求发现是包含了下划线。在百度和stackoverflow上查找问题发现,要求配置一下nginx,支持HTTP Header name支持下划线:

[quote]
[b]underscores_in_headers[/b] on | off;

Default: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.
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.[/quote]

但是nginx为什么要加这个配置呢,查找资料有的说HTTP Header name不能包含下划线。
翻了翻HTTP RFC,好像没有这个要求。
[b]3.2 Header Fields[/b]
[quote]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 "(),/:;<=>?@[\]{}").[/quote]

如果没理解错的话,HTTP header name应该可以包含下划线的。
还是下划线在nginx里有特殊用途,好像有的说是cgi会用到。
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值