Nginx的location指令
生活随笔
收集整理的這篇文章主要介紹了
Nginx的location指令
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
location指令
server{listen 80;server_name localhost;location / {}location /abc{}... }location:用來設置請求的URI
| 默認值 | — |
| 位置 | server,location |
uri變量是待匹配的請求字符串,可以不包含正則表達式,也可以包含正則表達式,那么nginx服務器在搜索匹配location的時候,是先使用不包含正則表達式進行匹配,找到一個匹配度最高的一個,然后在通過包含正則表達式的進行匹配,如果能匹配到直接訪問,匹配不到,就使用剛才匹配度最高的那個location來處理請求。
屬性介紹:
不帶符號,要求必須以指定模式開始
server {listen 80;server_name 127.0.0.1;location /abc{default_type text/plain;return 200 "access success";} } 以下訪問都是正確的 http://192.168.200.133/abc http://192.168.200.133/abc?p1=TOM http://192.168.200.133/abc/ http://192.168.200.133/abcdef= : 用于不包含正則表達式的uri前,必須與指定的模式精確匹配
server {listen 80;server_name 127.0.0.1;location =/abc{default_type text/plain;return 200 "access success";} } 可以匹配到 http://192.168.200.133/abc http://192.168.200.133/abc?p1=TOM 匹配不到 http://192.168.200.133/abc/ http://192.168.200.133/abcdef~ : 用于表示當前uri中包含了正則表達式,并且區(qū)分大小寫~*: 用于表示當前uri中包含了正則表達式,并且不區(qū)分大小寫
換句話說,如果uri包含了正則表達式,需要用上述兩個符合來標識
server {listen 80;server_name 127.0.0.1;location ~^/abc\w${default_type text/plain;return 200 "access success";} } server {listen 80;server_name 127.0.0.1;location ~*^/abc\w${default_type text/plain;return 200 "access success";} }^~: 用于不包含正則表達式的uri前,功能和不加符號的一致,唯一不同的是,如果模式匹配,那么就停止搜索其他模式了。
server {listen 80;server_name 127.0.0.1;location ^~/abc{default_type text/plain;return 200 "access success";} }總結
以上是生活随笔為你收集整理的Nginx的location指令的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Nginx的server_name匹配执
- 下一篇: Nginx的root和alias指令