nginx location中uri的截取的實(shí)現(xiàn)方法
說(shuō)明:
location 中的 root 和 alias
- root 指令只是將搜索的根設(shè)置為 root 設(shè)定的目錄,即不會(huì)截?cái)?uri,而是使用原始 uri 跳轉(zhuǎn)該目錄下查找文件
- aias 指令則會(huì)截?cái)嗥ヅ涞?uri,然后使用 alias 設(shè)定的路徑加上剩余的 uri 作為子路徑進(jìn)行查找
location 中的 proxy_pass 的 uri
如果 proxy_pass 的 url 不帶 uri
- 如果尾部是"/",則會(huì)截?cái)嗥ヅ涞膗ri
- 如果尾部不是"/",則不會(huì)截?cái)嗥ヅ涞膗ri
如果proxy_pass的url帶uri,則會(huì)截?cái)嗥ヅ涞膗ri
Examples
location中的 root
root@pts/1 $ ls -ld /data/web/lctest*|awk '{print $NF}' /data/web/lctest /data/web/lctest2 /data/web/lctest3 /data/web/lctest4 location /lctest { root /data/web/; } location /lctest2/ { root /data/web/; } location /lctest3 { root /data/web; } location /lctest4/ { root /data/web; }
curl 測(cè)試結(jié)果如下
備注: 瀏覽器輸入的時(shí)候最后面不添加 / , 會(huì)自動(dòng)補(bǔ)上,但是curl 不行
root@pts/1 $ curl http://tapi.xxxx.com/lctest/ hello world root@pts/1 $ curl http://tapi.xxxx.com/lctest2/ hello world 2 root@pts/1 $ curl http://tapi.xxxx.com/lctest3/ 3 hello world root@pts/1 $ curl http://tapi.xxxx.com/lctest4/ hello world 4
location alias
location /lctest5 { alias /data/web/; } location /lctest6/ { alias /data/web/; } location /lctest7 { alias /data/web; } ## 403 /data/web forbidden location /lctest8/ { alias /data/web; }
curl 測(cè)試結(jié)果如下
curl 'http://tapi.kaishustory.com/lctest5/' curl 'http://tapi.kaishustory.com/lctest6/' curl 'http://tapi.kaishustory.com/lctest7/' 結(jié)果都是 /data/web/index.html的輸出 root@pts/1 $ curl 'http://tapi.kaishustory.com/lctest8/' <html> <head><title>403 Forbidden</title></head> <body bgcolor="white"> <center><h1>403 Forbidden</h1></center> <hr><center>nginx</center> </body> </html>
location proxy_pass
#--------proxy_pass配置--------------------- location /t1/ { proxy_pass http://servers; } #正常,不截?cái)? location /t2/ { proxy_pass http://servers/; } #正常,截?cái)? location /t3 { proxy_pass http://servers; } #正常,不截?cái)? location /t4 { proxy_pass http://servers/; } #正常,截?cái)? location /t5/ { proxy_pass http://servers/test/; } #正常,截?cái)? location /t6/ { proxy_pass http://servers/test; } #缺"/",截?cái)? location /t7 { proxy_pass http://servers/test/; } #含"http://",截?cái)? location /t8 { proxy_pass http://servers/test; } #正常,截?cái)?
測(cè)試腳本
for i in $(seq 8) do url=http://tapi.xxxx.com/t$i/doc/index.html echo "-----------$url-----------" curl url done
測(cè)試結(jié)果
----------http://tapi.xxxx.com/t1/doc/index.html------------ /t1/doc/index.html ----------http://tapi.xxxx.com/t2/doc/index.html------------ /doc/index.html ----------http://tapi.xxxx.com/t3/doc/index.html------------ /t3/doc/index.html ----------http://tapi.xxxx.com/t4/doc/index.html------------ /doc/index.html ----------http://tapi.xxxx.com/t5/doc/index.html------------ /test/doc/index.html ----------http://tapi.xxxx.com/t6/doc/index.html------------ /testdoc/index.html ----------http://tapi.xxxx.com/t7/doc/index.html------------ /test//doc/index.html ----------http://tapi.xxxx.com/t8/doc/index.html------------ /test/doc/index.html
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Nginx配置指令location匹配符優(yōu)先級(jí)和安全問(wèn)題
- Nginx服務(wù)器中的location配置詳解
- 詳解nginx中l(wèi)ocation、rewrite用法總結(jié)
- 詳解Nginx location 匹配規(guī)則
- nginx location 配置 正則表達(dá)式實(shí)例詳解
- nginx?location/區(qū)別詳解
- Nginx服務(wù)器中l(wèi)ocation配置的一些基本要點(diǎn)解析
- 詳解nginx rewrite和根據(jù)url參數(shù)location
- nginx?配置指令之location使用詳解
- 深入解析nginx路由location匹配規(guī)則及其優(yōu)先級(jí)
相關(guān)文章
Nginx部署vue項(xiàng)目和配置代理的問(wèn)題解析
這篇文章主要介紹了Nginx部署vue項(xiàng)目和配置代理,需本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,要的朋友可以參考下2021-08-08nginx中配置使用proxy?protocol協(xié)議的全過(guò)程
proxy protocol是一個(gè)Internet協(xié)議,通過(guò)為tcp添加一個(gè)很小的頭信息,來(lái)方便的傳遞客戶(hù)端信息,在網(wǎng)絡(luò)情況復(fù)雜又需要獲取用戶(hù)真實(shí)IP時(shí)非常有用,這篇文章主要給大家介紹了關(guān)于nginx中配置使用proxy?protocol協(xié)議的相關(guān)資料,需要的朋友可以參考下2022-04-04nginx結(jié)合openssl實(shí)現(xiàn)https的方法
這篇文章主要介紹了基于nginx結(jié)合openssl實(shí)現(xiàn)https的方法,準(zhǔn)備工作大家需要安裝nginx服務(wù),具體操作過(guò)程跟隨小編一起看看吧2021-07-07Mac環(huán)境Nginx配置和訪問(wèn)本地靜態(tài)資源的實(shí)現(xiàn)
這篇文章主要介紹了Mac環(huán)境Nginx配置和訪問(wèn)本地靜態(tài)資源的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09解決Nginx無(wú)法啟動(dòng) -10013: An attempt was
這篇文章主要給大家介紹了解決用nginx -t 發(fā)成Nginx無(wú)法啟動(dòng)報(bào)錯(cuò)10013: An attempt was made to access a socket in a way forbidden by its access permissions的問(wèn)題,需要的朋友可以參考下2023-11-11詳解Nginx 被動(dòng)檢查服務(wù)器的存活狀態(tài)
Nginx 可以持續(xù)測(cè)試您的上游服務(wù)器,避免出現(xiàn)故障的服務(wù)器,并將恢復(fù)的服務(wù)器優(yōu)雅地添加到負(fù)載均衡組中。這篇文章主要介紹了Nginx 被動(dòng)檢查服務(wù)器的存活狀態(tài),需要的朋友可以參考下2021-10-10Nginx http運(yùn)行狀況健康檢查配置過(guò)程解析
這篇文章主要介紹了Nginx http運(yùn)行狀況健康檢查配置過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08