說明:
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 測試結(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 測試結(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/; } #含"//",截?cái)?location /t8 { proxy_pass http://servers/test; } #正常,截?cái)?/pre>測試腳本
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以上是nginx location中uri的截取如何實(shí)現(xiàn)的詳細(xì)內(nèi)容。更多信息請關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

熱AI工具

Undress AI Tool
免費(fèi)脫衣服圖片

Undresser.AI Undress
人工智能驅(qū)動(dòng)的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover
用于從照片中去除衣服的在線人工智能工具。

Clothoff.io
AI脫衣機(jī)

Video Face Swap
使用我們完全免費(fèi)的人工智能換臉工具輕松在任何視頻中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費(fèi)的代碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
功能強(qiáng)大的PHP集成開發(fā)環(huán)境

Dreamweaver CS6
視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版
神級代碼編輯軟件(SublimeText3)

Docker 容器啟動(dòng)步驟:拉取容器鏡像:運(yùn)行 "docker pull [鏡像名稱]"。創(chuàng)建容器:使用 "docker create [選項(xiàng)] [鏡像名稱] [命令和參數(shù)]"。啟動(dòng)容器:執(zhí)行 "docker start [容器名稱或 ID]"。檢查容器狀態(tài):通過 "docker ps" 驗(yàn)證容器是否正在運(yùn)行。

可以通過以下步驟查詢 Docker 容器名稱:列出所有容器(docker ps)。篩選容器列表(使用 grep 命令)。獲取容器名稱(位于 "NAMES" 列中)。

確認(rèn) Nginx 是否啟動(dòng)的方法:1. 使用命令行:systemctl status nginx(Linux/Unix)、netstat -ano | findstr 80(Windows);2. 檢查端口 80 是否開放;3. 查看系統(tǒng)日志中 Nginx 啟動(dòng)消息;4. 使用第三方工具,如 Nagios、Zabbix、Icinga。

在 Docker 中創(chuàng)建容器: 1. 拉取鏡像: docker pull [鏡像名] 2. 創(chuàng)建容器: docker run [選項(xiàng)] [鏡像名] [命令] 3. 啟動(dòng)容器: docker start [容器名]

問題:如何啟動(dòng) Nginx?答案:安裝 Nginx啟動(dòng) Nginx驗(yàn)證 Nginx 是否已啟動(dòng)探索其他啟動(dòng)選項(xiàng)自動(dòng)啟動(dòng) Nginx

NGINX和Apache各有優(yōu)劣,適合不同場景。1.NGINX適合高并發(fā)和低資源消耗場景。2.Apache適合需要復(fù)雜配置和豐富模塊的場景。通過比較它們的核心特性、性能差異和最佳實(shí)踐,可以幫助你選擇最適合需求的服務(wù)器軟件。

提升CentOS系統(tǒng)下PhpStorm性能的實(shí)用技巧本文提供多種方法,幫助您優(yōu)化CentOS系統(tǒng)中PhpStorm的性能,從而提高開發(fā)效率。在實(shí)施任何優(yōu)化措施前,請務(wù)必備份重要數(shù)據(jù)并在測試環(huán)境中驗(yàn)證效果。一、系統(tǒng)級優(yōu)化精簡系統(tǒng)服務(wù):禁用不必要的系統(tǒng)服務(wù)和守護(hù)進(jìn)程,減少系統(tǒng)資源占用。無界面模式:如果不需要圖形界面,切換到無界面模式可顯著節(jié)省資源。卸載冗余軟件:移除不再使用的軟件包和服務(wù),釋放系統(tǒng)資源。二、PHP配置優(yōu)化啟用OPcache:安裝并配置OPcache擴(kuò)展,顯

NGINX和Apache都是強(qiáng)大的Web服務(wù)器,各自在性能、可擴(kuò)展性和效率上有獨(dú)特的優(yōu)勢和不足。1)NGINX在處理靜態(tài)內(nèi)容和反向代理時(shí)表現(xiàn)出色,適合高并發(fā)場景。2)Apache在處理動(dòng)態(tài)內(nèi)容時(shí)表現(xiàn)更好,適合需要豐富模塊支持的項(xiàng)目。選擇服務(wù)器應(yīng)根據(jù)項(xiàng)目需求和場景來決定。
