nginx location中uri的截取的實現(xiàn)方法
說明:
location 中的 root 和 alias
- root 指令只是將搜索的根設置為 root 設定的目錄,即不會截斷 uri,而是使用原始 uri 跳轉(zhuǎn)該目錄下查找文件
- aias 指令則會截斷匹配的 uri,然后使用 alias 設定的路徑加上剩余的 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)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- Nginx配置指令location匹配符優(yōu)先級和安全問題
- Nginx服務器中的location配置詳解
- 詳解nginx中l(wèi)ocation、rewrite用法總結(jié)
- 詳解Nginx location 匹配規(guī)則
- nginx location 配置 正則表達式實例詳解
- nginx?location/區(qū)別詳解
- Nginx服務器中l(wèi)ocation配置的一些基本要點解析
- 詳解nginx rewrite和根據(jù)url參數(shù)location
- nginx?配置指令之location使用詳解
- 深入解析nginx路由location匹配規(guī)則及其優(yōu)先級
相關(guān)文章
nginx如何實現(xiàn)同個ip、端口訪問不同的項目(以路徑區(qū)分項目)
這篇文章主要介紹了nginx如何實現(xiàn)同個ip、端口訪問不同的項目(以路徑區(qū)分項目),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-12-12
Nginx啟動成功卻無法訪問網(wǎng)頁的問題分析和解決方案(完整的排除方案)
我是用的阿里云的服務器,所以我的問題就在于阿里云服務器必須單獨開端口,在找到這個問題之前,我已經(jīng)把所有能試的方法試過了一遍都沒有問題,在增加端口之后直接成功了,如果你也遇到了這樣的問題,就和我一起排除吧2023-12-12
詳解nginx前端根據(jù)$remote_addr分發(fā)方法
這篇文章主要介紹了詳解nginx前端根據(jù)$remote_addr分發(fā)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-11-11
詳解Nginx如何根據(jù)swagger關(guān)鍵字屏蔽頁面
這篇文章主要為大家詳細介紹了Nginx 如何根據(jù)swagger關(guān)鍵字屏蔽頁面的實現(xiàn)方案,文中有詳細的解決方案,對我們的學習或工作有一定的幫助,需要的朋友可以參考下2023-08-08

