<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                location = / { # 精確匹配 / ,主機名后面不能帶任何字符串 [ configuration A ] } location / { # 因為所有的地址都以 / 開頭,所以這條規則將匹配到所有請求 # 但是正則和最長字符串會優先匹配 [ configuration B ] } location /documents/ { # 匹配任何以 /documents/ 開頭的地址,匹配符合以后,還要繼續往下搜索 # 只有后面的正則表達式沒有匹配到時,這一條才會采用這一條 [ configuration C ] } location ~ /documents/Abc { # 匹配任何以 /documents/Abc 開頭的地址,匹配符合以后,還要繼續往下搜索 # 只有后面的正則表達式沒有匹配到時,這一條才會采用這一條 [ configuration CC ] } location ^~ /images/ { # 匹配任何以 /images/ 開頭的地址,匹配符合以后,停止往下搜索正則,采用這一條。 [ configuration D ] } location ~* \.(gif|jpg|jpeg)$ { # 匹配所有以 gif,jpg或jpeg 結尾的請求 # 然而,所有請求 /images/ 下的圖片會被 config D 處理,因為 ^~ 到達不了這一條正則 [ configuration E ] } location /images/ { # 字符匹配到 /images/,繼續往下,會發現 ^~ 存在 [ configuration F ] } location /images/abc { # 最長字符匹配到 /images/abc,繼續往下,會發現 ^~ 存在 # F與G的放置順序是沒有關系的 [ configuration G ] } location ~ /images/abc/ { # 只有去掉 config D 才有效:先最長匹配 config G 開頭的地址,繼續往下搜索,匹配到這一條正則,采用 [ configuration H ] } location ~* /js/.*/\.js * 已`=`開頭表示精確匹配 如 A 中只匹配根目錄結尾的請求,后面不能帶任何字符串。 * `^~`開頭表示uri以某個常規字符串開頭,不是正則匹配 * ~ 開頭表示區分大小寫的正則匹配; * ~\* 開頭表示不區分大小寫的正則匹配 * / 通用匹配, 如果沒有其它匹配,任何請求都會匹配到 ## 優先級 (location =) > (location 完整路徑) > (location ^~ 路徑) > (location ~,~\* 正則順序) > (location 部分起始路徑) > (/) 上面的匹配結果 按照上面的location寫法,以下的匹配示例成立: * / -> config A 精確完全匹配,即使/index.html也匹配不了 * /downloads/download.html -> config B 匹配B以后,往下沒有任何匹配,采用B * /images/1.gif -> configuration D 匹配到F,往下匹配到D,停止往下 * /images/abc/def -> config D 最長匹配到G,往下匹配D,停止往下 你可以看到 任何以/images/開頭的都會匹配到D并停止,FG寫在這里是沒有任何意義的,H是永遠輪不到的,這里只是為了說明匹配順序 * /documents/document.html -> config C 匹配到C,往下沒有任何匹配,采用C * /documents/1.jpg -> configuration E 匹配到C,往下正則匹配到E * /documents/Abc.jpg -> config CC 最長匹配到C,往下正則順序匹配到CC,不會往下到E 所以實際使用中,個人覺得至少有三個匹配規則定義,如下: #直接匹配網站根,通過域名訪問網站首頁比較頻繁,使用這個會加速處理,官網如是說。 #這里是直接轉發給后端應用服務器了,也可以是一個靜態首頁 # 第一個必選規則 location = / { proxy_pass http://tomcat:8080/index } # 第二個必選規則是處理靜態文件請求,這是nginx作為http服務器的強項 # 有兩種配置模式,目錄匹配或后綴匹配,任選其一或搭配使用 location ^~ /static/ { root /webroot/static/; } location ~* \.(gif|jpg|jpeg|png|css|js|ico)$ { root /webroot/res/; } #第三個規則就是通用規則,用來轉發動態請求到后端應用服務器 #非靜態文件請求就默認是動態請求,自己根據實際把握 #畢竟目前的一些框架的流行,帶.php,.jsp后綴的情況很少了 location / { proxy_pass http://tomcat:8080/ } ## 參考 [http://tengine.taobao.org/book/chapter\_02.html](http://tengine.taobao.org/book/chapter_02.html) [http://nginx.org/en/docs/http/ngx\_http\_rewrite\_module.html](http://nginx.org/en/docs/http/ngx_http_rewrite_module.html)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看