1. 程式人生 > >Nginx-location模塊

Nginx-location模塊

conf location 區別 cati python ... ati pre 根據

Nginx-location模塊

location作用

location的作用是根據用戶請求的URL來執行不同的應用。根據用戶請求的網站地址URL進行匹配,匹配成功

即進行相關操作。

location語法

#語法
location [ = | ~ | ~* | ^~ ] url {
...
}

#說明
location        指令
[=|~|~*|@]  匹配標識
url               匹配的網站網址
{...}            匹配URL後要執行的配置段


#匹配這兩種特殊字符 “~”或“~*”的區別:
“~”用於區分大小寫(大小寫敏感)匹配
"~*"用於不區分大小寫的匹配
"!"對上面的匹配取反,如("!~"和"!~*")
"^"作用是在進行常規的字符匹配後,不做正則表達式檢查

location匹配示例

#官方例子
location = /{
     [ configuration A ]        
}
#用戶請求URL:/    
#完整URL:http://www.hello.com/



location /{
     [ configuration B ]        
}
#用戶請求URL:/index.html    
#完整URL:http://www.hello.com/


location /documents/ {
     [ configuration C ]        
}
#用戶請求URL:/documents/document.html
#完整URL:http://www.hello.com/documents/document.html



location ^~ /images/ {
     [ configuration D ]        
}
#用戶請求URL:/images/1.gif
#完整URL:http://www.hello.com/images/1.gif



location ~* \.(gif|jpg|jpge)$ {
     [ configuration E ]        
}
#用戶請求URL:/documents/1.gif
#完整URL:http://www.hello.com/documents/1.gif

Nginx-location模塊