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 溫水青蛙 閱讀(2054) 評論(1)  編輯  收藏

          評論

          # re: nginx處理HTTP header問題 2016-05-27 19:53 sAka
          感謝您的經驗,萬分感謝。  回復  更多評論
            


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 蛟河市| 青川县| 常熟市| 阿尔山市| 赤峰市| 织金县| 佳木斯市| 柘城县| 思南县| 陵川县| 休宁县| 靖江市| 瑞昌市| 灌南县| 阿拉善盟| 托克托县| 逊克县| 五寨县| 武乡县| 巢湖市| 罗源县| 沙洋县| 巴彦县| 介休市| 澎湖县| 社会| 西昌市| 木兰县| 南岸区| 永清县| 乐业县| 义马市| 洛扎县| 安化县| 波密县| 新绛县| 资阳市| 潜江市| 鹤山市| 常宁市| 柘荣县|