码迷,mamicode.com
首页 > Web开发 > 详细

[nginx][http] nginx关于http header的设置

时间:2020-04-20 13:33:25      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:HERE   ons   存在   receive   方法   serve   一个   返回   sign   

nginx关于http header有以下三个配置。

1 proxy_set_header

https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_set_header

配置命令proxy_set_header,是在ngx_http_proxy_module里边定义的。

用来对http request header进行修改。

 

2 add_header

https://nginx.org/en/docs/http/ngx_http_headers_module.html#add_header

配置命令 add_header,是在ngx_http_headers_module里边定义的。

用来对http server返回的http response header进行修改,

修改的方法是,追加的在header的最前面。

 

3 add_tailer

http://nginx.org/en/docs/http/ngx_http_headers_module.html#add_trailer

配置命令 add_tailer,是在ngx_http_headers_module里边定义的。

功能与add_header相同,区别是添加在header的结尾。

 

4 http header的顺序

既然有了添加到开头或者添加到结尾的区别。那么不禁要问,http header里边的KV结构是否存在顺序区别呢?

通过阅读rfc 2616,可以了解到如下内容:

rfc对http的header顺序没有强制要求,但是一个好的最佳实践一般是:

依次应该为:general-header,  request-header or response-header,  entity-header.

The order in which header fields with differing field names are received is not significant. However, 
it is "good practice" to send general-header fields first, followed by request-header
or response- header fields, and ending with the entity-header fields.

 

另外, 如果有多个名字相同的header存在时,“实现”应该将他们的值压缩在一起,用逗号分隔。

逗号分隔后的内容是否包含了顺序信息应该有通讯两端定义,作为中间人的proxy不应该修改他们。

Multiple message-header fields with the same field-name MAY be present in a message if and only if
the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)].
It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair,
without changing the semantics of the message, by appending each subsequent field-value to the
first, each separated by a comma. The order in which header fields with the same field-name are
received is therefore significant to the interpretation of the combined field value,
and thus a proxy MUST NOT change the order of these field values when a message is forwarded.

 

[nginx][http] nginx关于http header的设置

标签:HERE   ons   存在   receive   方法   serve   一个   返回   sign   

原文地址:https://www.cnblogs.com/hugetong/p/12737012.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!