<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # location 匹配規則 #### 語法規則 location [=|~|~*|^~] /uri/ { … } | 符號 | 含義 | |-----|-----| | = | 開頭表示精確匹配 | | ^~ | 開頭表示uri以某個常規字符串開頭,理解為匹配 url路徑即可。nginx不對url做編碼,因此請求為`/static/20%/aa`,可以被規則`^~ /static/ /aa`匹配到(注意是空格) | | ~ | 開頭表示區分大小寫的正則匹配 | | ~* | 開頭表示不區分大小寫的正則匹配 | | !~和!~* | 分別為區分大小寫不匹配及不區分大小寫不匹配 的正則 | | / | 通用匹配,任何請求都會匹配到。 | 多個location配置的情況下匹配順序為(參考資料而來,還未實際驗證,試試就知道了,不必拘泥,僅供參考): - 首先匹配 `=` - 其次匹配 `^~` - 其次是按文件中順序的正則匹配 - 最后是交給 `/` 通用匹配 - 當有匹配成功時候,停止匹配,按當前匹配規則處理請求 例子,有如下匹配規則: ~~~ location = / { #規則A } location = /login { #規則B } location ^~ /static/ { #規則C } location ~ \.(gif|jpg|png|js|css)$ { #規則D } location ~* \.png$ { #規則E } location !~ \.xhtml$ { #規則F } location !~* \.xhtml$ { #規則G } location / { #規則H } ~~~ 那么產生的效果如下: - 訪問根目錄/, 比如[http://localhost/](http://localhost/) 將匹配規則A - 訪問 [http://localhost/login](http://localhost/login) 將匹配規則B,[http://localhost/register](http://localhost/register) 則匹配規則H - 訪問 [http://localhost/static/a.html](http://localhost/static/a.html) 將匹配規則C - 訪問 [http://localhost/a.gif](http://localhost/a.gif), [http://localhost/b.jpg](http://localhost/b.jpg) 將匹配規則D和規則E,但是規則D順序優先,規則E不起作用,而 [http://localhost/static/c.png](http://localhost/static/c.png) 則優先匹配到規則C - 訪問 [http://localhost/a.PNG](http://localhost/a.PNG) 則匹配規則E,而不會匹配規則D,因為規則E不區分大小寫。 - 訪問 [http://localhost/a.xhtml](http://localhost/a.xhtml) 不會匹配規則F和規則G,[http://localhost/a.XHTML不會匹配規則G,因為不區分大小寫。規則F,規則G屬于排除法,符合匹配規則但是不會匹配到,所以想想看實際應用中哪里會用到。](http://localhost/a.XHTML不會匹配規則G,因為不區分大小寫。規則F,規則G屬于排除法,符合匹配規則但是不會匹配到,所以想想看實際應用中哪里會用到。) 訪問 [http://localhost/category/id/1111](http://localhost/category/id/1111) 則最終匹配到規則H,因為以上規則都不匹配,這個時候應該是nginx轉發請求給后端應用服務器,比如FastCGI(php),tomcat(jsp),nginx作為方向代理服務器存在。 所以實際使用中,個人覺得至少有三個匹配規則定義,如下: ~~~ #直接匹配網站根,通過域名訪問網站首頁比較頻繁,使用這個會加速處理,官網如是說。 #這里是直接轉發給后端應用服務器了,也可以是一個靜態首頁 # 第一個必選規則 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/ } ~~~ #### ReWrite語法 - last – 基本上都用這個Flag - break – 中止Rewirte,不在繼續匹配 - redirect – 返回臨時重定向的HTTP狀態302 - permanent – 返回永久重定向的HTTP狀態301 1、下面是可以用來判斷的表達式: ~~~ -f和!-f用來判斷是否存在文件 -d和!-d用來判斷是否存在目錄 -e和!-e用來判斷是否存在文件或目錄 -x和!-x用來判斷文件是否可執行 ~~~ 2、下面是可以用作判斷的全局變量 ~~~ 例:http://localhost:88/test1/test2/test.php $host:localhost $server_port:88 $request_uri:http://localhost:88/test1/test2/test.php $document_uri:/test1/test2/test.php $document_root:D:\nginx/html $request_filename:D:\nginx/html/test1/test2/test.php ~~~ #### Redirect語法 ~~~ server { listen 80; server_name start.igrow.cn; index index.html index.php; root html; if ($http_host !~ “^star\.igrow\.cn$&quot { rewrite ^(.*) http://star.igrow.cn$1 redirect; } } ~~~ #### 防盜鏈 ~~~ location ~* \.(gif|jpg|swf)$ { valid_referers none blocked start.igrow.cn sta.igrow.cn; if ($invalid_referer) { rewrite ^/ http://$host/logo.png; } } ~~~ #### 根據文件類型設置過期時間 ~~~ location ~* \.(js|css|jpg|jpeg|gif|png|swf)$ { if (-f $request_filename) { expires 1h; break; } } ~~~ #### 禁止訪問某個目錄 ~~~ location ~* \.(txt|doc)${ root /data/www/wwwroot/linuxtone/test; deny all; } ~~~ 一些可用的全局變量,可以參考[獲取Nginx內置綁定變量](#)章節。
                  <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>

                              哎呀哎呀视频在线观看