nginx location中uri的截取的實現(xiàn)方法
說明:
location 中的 root 和 alias
- root 指令只是將搜索的根設(shè)置為 root 設(shè)定的目錄,即不會截斷 uri,而是使用原始 uri 跳轉(zhuǎn)該目錄下查找文件
- aias 指令則會截斷匹配的 uri,然后使用 alias 設(shè)定的路徑加上剩余的 uri 作為子路徑進行查找
location 中的 proxy_pass 的 uri
如果 proxy_pass 的 url 不帶 uri
- 如果尾部是"/",則會截斷匹配的uri
- 如果尾部不是"/",則不會截斷匹配的uri
如果proxy_pass的url帶uri,則會截斷匹配的uri
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 測試結(jié)果如下
備注: 瀏覽器輸入的時候最后面不添加 / , 會自動補上,但是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 測試結(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; } #正常,不截斷 location /t2/ { proxy_pass http://servers/; } #正常,截斷 location /t3 { proxy_pass http://servers; } #正常,不截斷 location /t4 { proxy_pass http://servers/; } #正常,截斷 location /t5/ { proxy_pass http://servers/test/; } #正常,截斷 location /t6/ { proxy_pass http://servers/test; } #缺"/",截斷 location /t7 { proxy_pass http://servers/test/; } #含"http://",截斷 location /t8 { proxy_pass http://servers/test; } #正常,截斷
測試腳本
for i in $(seq 8) do url=http://tapi.xxxx.com/t$i/doc/index.html echo "-----------$url-----------" curl url done
測試結(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
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Nginx配置指令location匹配符優(yōu)先級和安全問題
- Nginx服務(wù)器中的location配置詳解
- 詳解nginx中l(wèi)ocation、rewrite用法總結(jié)
- 詳解Nginx location 匹配規(guī)則
- nginx location 配置 正則表達式實例詳解
- nginx?location/區(qū)別詳解
- Nginx服務(wù)器中l(wèi)ocation配置的一些基本要點解析
- 詳解nginx rewrite和根據(jù)url參數(shù)location
- nginx?配置指令之location使用詳解
- 深入解析nginx路由location匹配規(guī)則及其優(yōu)先級
相關(guān)文章
nginx中配置使用proxy?protocol協(xié)議的全過程
proxy protocol是一個Internet協(xié)議,通過為tcp添加一個很小的頭信息,來方便的傳遞客戶端信息,在網(wǎng)絡(luò)情況復(fù)雜又需要獲取用戶真實IP時非常有用,這篇文章主要給大家介紹了關(guān)于nginx中配置使用proxy?protocol協(xié)議的相關(guān)資料,需要的朋友可以參考下2022-04-04nginx結(jié)合openssl實現(xiàn)https的方法
這篇文章主要介紹了基于nginx結(jié)合openssl實現(xiàn)https的方法,準(zhǔn)備工作大家需要安裝nginx服務(wù),具體操作過程跟隨小編一起看看吧2021-07-07Mac環(huán)境Nginx配置和訪問本地靜態(tài)資源的實現(xiàn)
這篇文章主要介紹了Mac環(huán)境Nginx配置和訪問本地靜態(tài)資源的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09解決Nginx無法啟動 -10013: An attempt was
這篇文章主要給大家介紹了解決用nginx -t 發(fā)成Nginx無法啟動報錯10013: An attempt was made to access a socket in a way forbidden by its access permissions的問題,需要的朋友可以參考下2023-11-11