title: nginx中l(wèi)ocation細(xì)節(jié)解析
date: 2016-12-16 11:23:56
tags: nginx location
categories: nginx
location模塊的路徑匹配流程圖:
image.png
可以簡單記為起作用的順序是
=(精準(zhǔn)匹配) > (^~字符串前綴匹配即碗,不考慮正則結(jié)果) > (正則location匹配和*) > (字符串前綴匹配)
其中多個匹配的正則location起作用的順序跟在conf文件中的順序相關(guān)
location中的其他常見指令
root 尋址開始的根
可以在server context和location context下定義root客冈,但是通常
為了避免冗余配置乾蓬,在server上下文中配置一個root最好
error_page 錯誤頁面
error_page 404 /404.html
可以單獨(dú)配置在其中一個location模塊中
location /a {
root /Users/tobi/Pictures/;
error_page 404.html #放在上述目錄下的/Users/tobi/Pictures/a/404.html
}
或者單獨(dú)為error_page配置一個地址
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}