国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

nginx url rewriting: difference between break and

BDEEFE / 2897人閱讀

Example 1: No (break or last) flags
server {
    server_name example.com;
    root "path/to/somewhere";

    location / {
        echo "finally matched location /";
    }

    location /notes {
        echo "finally matched location /notes";
    }

    location /documents {
        echo "finally matched location /documents";
    }

    rewrite ^/([^/]+.txt)$ /notes/$1;
    rewrite ^/notes/([^/]+.txt)$ /documents/$1;
}
Result:
#curl example.com/test.txt
finally matched location /documents
Explanation:

For rewrite, the flags are optional!

Example 2: Outside location block (break or last)
server {
    server_name example.com;
    root "path/to/somewhere";

    location / {
        echo "finally matched location /";
    }

    location /notes {
        echo "finally matched location /notes";
    }

    location /documents {
        echo "finally matched location /documents";
    }

    rewrite ^/([^/]+.txt)$ /notes/$1 break; # or last
    rewrite ^/notes/([^/]+.txt)$ /documents/$1; # this is not parsed
}
Result:
#curl example.com/test.txt
finally matched location /notes
Explanation:

Outside the location block, both break and last behave in the exact manner...

no more parsing of rewrite conditions
Nginx internal engine goes to the next phase (searching for location match)

Example 3: Inside location block - "break"
server {
    server_name example.com;
    root "path/to/somewhere";

    location / {
        echo "finally matched location /";
        rewrite ^/([^/]+.txt)$ /notes/$1 break;
        rewrite ^/notes/([^/]+.txt)$ /documents/$1; # this is not parsed
    }

    location /notes {
        echo "finally matched location /notes";
    }

    location /documents {
        echo "finally matched location /documents";
    }
}
Result:
# curl example.com/test.txt
finally matched location /
Explanation:

Inside a location block, break flag would do the following...

no more parsing of rewrite conditions
Nginx internal engine continues to parse the current location block

Example 4: Inside location block - "last"
server {
    server_name example.com;
    root "path/to/somewhere";

    location / {
        echo "finally matched location /";
        rewrite ^/([^/]+.txt)$ /notes/$1 last;
        rewrite ^/notes/([^/]+.txt)$ /documents/$1;  # this is not parsed
    }

    location /notes {
        echo "finally matched location /notes";
        rewrite ^/notes/([^/]+.txt)$ /documents/$1;  # this is not parsed, either!
    }

    location /documents {
        echo "finally matched location /documents";
    }
}
Result:
# curl example.com/test.txt
finally matched location /notes
Explanation:

Inside a location block, last flag would do the following...

no more parsing of rewrite conditions
Nginx internal engine starts to look for another location match based on the result of the rewrite result.
no more parsing of rewrite conditions, even on the next location match!

Summary:

When a rewrite condition with the flag break or last matches, Nginx stops parsing any more rewrites!
Outside a location block, with break or last, Nginx does the same job (stops processing anymore rewrite conditions).
Inside a location block, with break, Nginx only stops processing anymore rewrite conditions
Inside a location block, with last, Nginx stops processing anymore rewrite conditions and then starts to look for a new matching of location block! Nginx also ignores any rewrites in the new location block!

Final Note:

missed to include some more edge cases (actually common problem with rewrites, such as 500 internal error). But, that"d be out of scope of this question. Probably, example 1 is out of scope, too!

鏈接:https://serverfault.com/quest...

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/39884.html

相關文章

  • nginx rewrite配置解讀

    序 本文主要解析一下ngx_http_rewrite_module中的rewrite相關配置。 directives 名稱 默認配置 作用域 官方說明 中文解讀 模塊 break 無 server, location, if Stops processing the current set of ngx_http_rewrite_module directives. 中斷當前的重寫 ng...

    IamDLY 評論0 收藏0
  • nginx(二):進階配置介紹--rewrite用法,壓縮,https虛擬主機等

    摘要:經由超文本傳輸協議通信,但是數據包由安全協議加密,實現加密數據與認證功能。該模塊指令定義相關設置證書文件,私鑰文件,會話緩存等內容。允許在客戶端建立會話時傳遞請求服務器名稱,這樣服務器就會知道該發送哪個虛擬主機下的證書文件。 1、nginx基本狀態信息頁面 配置示例: location /basic_status { stub_...

    JayChen 評論0 收藏0
  • nginx 常用配置記錄

    摘要:如果狀態碼附帶文字段落,該文本將被放置在響應主體。相反,如果狀態碼后面是一個,該將成為頭部值。沒有狀態碼的將被視為一個狀態碼,這種情況下需要以或者開頭。因為和不能簡單的只返回狀態碼,還必須有重定向的,這就是指令無法返回的原因了。 HTTP模塊(核心模塊,也是主要用到的模塊) server模塊 server模塊是http的子模塊,它用來定義一個虛擬主機 例子: server { ...

    Youngs 評論0 收藏0
  • Nginx rewrite配置規則

    摘要:語法規則定向路徑重寫類型規則可以是字符串或者正則來表示想匹配的目標定向路徑表示匹配到規則后要定向的路徑,如果規則里有正則,則可以使用來表示正則里的捕獲分組重寫類型相當于里德標記,表示完成,瀏覽器地址欄地址不變本條規則匹配完成后,終止匹配,不 rewrite語法 server { rewrite {規則} {定向路徑} {重寫類型} ; } 1、規則:可以是字符串或者正則來表示想...

    gggggggbong 評論0 收藏0
  • 搞懂nginx的rewrite模塊

    摘要:非標準碼關閉連接而不發送響應報頭。指令按照它們在配置文件中出現的順序執行??梢允褂脴酥緛斫K止指令的進一步處理。返回永久重定向。發送如下請求控制是否記錄有關未初始化變量的警告。 之前在配置nginx時,總是遇到rewrite指令的last和break標識的問題,看到的資料大都是last 基本上都用這個 Flag,break 中止 Rewirte,不在繼續匹配??赐曛筮€是有點懵,后來看了...

    wangshijun 評論0 收藏0

發表評論

0條評論

最新活動
閱讀需要支付1元查看
<