iamhuzl

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            1 隨筆 :: 13 文章 :: 21 評(píng)論 :: 0 Trackbacks
              由于80端口需要root用戶才能使用,所以tomcat都是root用戶管理的,為了安全起見昨天安裝了一個(gè)nginx作為反向代理,tomcat改為8080端口。但測(cè)試發(fā)現(xiàn)有幾個(gè)接口一直報(bào)錯(cuò),幾個(gè)HTTP頭取不到值,比對(duì)其他請(qǐng)求發(fā)現(xiàn)是包含了下劃線。在百度和stackoverflow上查找問題發(fā)現(xiàn),要求配置一下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為什么要加這個(gè)配置呢,查找資料有的說HTTP Header name不能包含下劃線。
          翻了翻HTTP RFC,好像沒有這個(gè)要求。

          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
          的范思科表達(dá)式定義:
          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 "(),/:;<=>?@[\]{}").

          如果沒理解錯(cuò)的話,HTTP header name應(yīng)該可以包含下劃線的。
          還是下劃線在nginx里有特殊用途,好像有的說是cgi會(huì)用到。
          posted on 2014-07-10 12:37 溫水青蛙 閱讀(2053) 評(píng)論(1)  編輯  收藏

          評(píng)論

          # re: nginx處理HTTP header問題 2016-05-27 19:53 sAka
          感謝您的經(jīng)驗(yàn),萬分感謝。  回復(fù)  更多評(píng)論
            


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 柯坪县| 天峨县| 时尚| 襄垣县| 兴山县| 娄烦县| 澄城县| 榕江县| 天门市| 诸城市| 丹东市| 进贤县| 金平| 亚东县| 洛阳市| 格尔木市| 景洪市| 宜黄县| 大埔县| 荔浦县| 临洮县| 常德市| 青田县| 合阳县| 聂荣县| 象山县| 枞阳县| 安化县| 徐闻县| 岑溪市| 潢川县| 崇左市| 民县| 田东县| 磐石市| 施秉县| 乐业县| 望都县| 金塔县| 台山市| 长治县|