3.location块的路径映射

优先级关系:精准(=)匹配 > 完整路径匹配 > 开头(^~)匹配 > 正则(~)匹配 > 通用匹配

# 精准匹配,主机名后面不能带能和字符串
location = / {	
	# 例如www.baidu.com不能是www.baidu.com/id=xxx
}

# 通用匹配,匹配所有以/xxx开头的路径
location /xxx {
	# 例如127.0.0.1:8080/xxx	xxx可以为空,为空则和=匹配一样
}

# 正则匹配,匹配所有以/xxx开头的路径,优先级高于通用匹配
location ~ /xxx {
}

# 匹配开头路径,匹配所有以/images/开头的路径
location ^~ /images/ {
}

# 匹配结尾路径,匹配以gif、jpg或者png为结尾的路径
location ~* \.(gif/jpg/png)$ {
}
posted @ 2021-01-21 16:13  ctrl_cv_luo  阅读(111)  评论(0编辑  收藏  举报