實(shí)例區(qū)分nginxlocation中rewrite的break與last -電腦資料

電腦資料 時(shí)間:2019-01-01 我要投稿
【clearvueentertainment.com - 電腦資料】

    驗(yàn)證代碼:

server{listen 80;server_name www.example.com;location ~ /test1.txt {rewrite /test1.txt /test2.txt break;#rewrite /test1.txt /test2.txt last;}location ~ /test2.txt {root /var/txt/;}}

    文件設(shè)置:

    驗(yàn)證 rewrite /test1.txt /test2.txt break; 在 /usr/local/nginx/html 有test2.txt 內(nèi)容為 /usr/local/nginx/html/test2

    驗(yàn)證 rewrite /test1.txt /test2.txt last; 在/var/txt/ 有test2.txt 內(nèi)容為 /var/test2

    說(shuō)明:

    在使用break時(shí),www.example.com/test1.txt rewrite 為 www.example.com/test2.txt 不向下邊的location中查找,我們會(huì)查看到 /usr/local/nginx/html/test2,說(shuō)明是/usr/local/nginx/html中的test2.txt

    (last其實(shí)就相當(dāng)于一個(gè)新的url,對(duì)nginx進(jìn)行了一次請(qǐng)求,需要走一遍大多數(shù)的處理過(guò)程,最重要的是會(huì)做一次find config,提供了一個(gè)可以轉(zhuǎn)到其他location的配置中處理的機(jī)會(huì),)

    在使用last時(shí),www.example.com/test1.txt rewrite 為 www.example.com/test2.txt 并匹配下邊的location,

實(shí)例區(qū)分nginxlocation中rewrite的break與last

電腦資料

實(shí)例區(qū)分nginxlocation中rewrite的break與last》(http://clearvueentertainment.com)。我們會(huì)查看到 /var/test2

    (break則是在一個(gè)請(qǐng)求處理過(guò)程中將原來(lái)的url(包括uri和args)改寫(xiě)之后,在繼續(xù)進(jìn)行后面的處理,這個(gè)重寫(xiě)之后的請(qǐng)求始終都是在同一個(gè)location中處理。)

最新文章