Nginx location 使用正则匹配路径

105 阅读1分钟

Nginx location 使用正则匹配路径

配置的方式

~~* 加正则表达式

~* [正则表达式] 不区分大小写

~ [正则表达式] 区分大小写

server {
	listen 80;
	
	# 匹配.xml结尾的文件 不区分大小写
	# url不区分大小写但访问test.XML匹配不到test.xml文件
	location ~* \.(xml)$ {
		root /usr/share/nginx/files/seo/;
	}
	
	# 匹配robots.txt文件
	location ~ robots.txt$ {
		root /usr/share/nginx/files/seo/;
	}
}