windows 安装
下载nginx
包,然后存放到目录中
双击运行nginx.exe
配置
在
conf/nginx.conf
文件里面进行相关配置
需求说明:在访问路径
/test/
下面的html等资源的时候查找路径/usr/local
下面的路径,需要屏蔽/test-a/a.html
等其他路径配置如下:
1
2
3location ~ ^/test/.*\.(html|png|css|js|woff2) {
root D:\server;
}将静态资源
test(一堆文件)
存放到D:\server
下面即可。运行
nginx.exe
即可
配置解析
nginx 路径符号匹配
=
: 精确匹配^~
: uri以某个常规字符串开头,大多情况下用来匹配url路径,nginx不对url做编码~
: 正则匹配(区分大小写)~*
: 正则匹配(不区分大小写)!~
和!~*
: 分别为区分大小写不匹配及不区分大小写不匹配 的正则/
: 任何请求都会匹配符号优先级
首先匹配=
,其次匹配^~
, 其次是按文件中顺序的正则匹配,最后是交给/
通用匹配。当有匹配成功时候,停止匹配,按当前匹配规则处理请求。简单通用配置
静态动态分离,除了静态资源以外的请求都交给Tomcat处理.1
2
3
4
5
6
7
8
9
10
11location / {
proxy_pass http://localhost:8080
}
location ^~ /static/ {
root /webroot/static/;
}
location ~* \.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
root /webroot/res/;
}正则提示:
链接 -> https://c.runoob.com/front-end/854/
排除某个单词如:排除A后+ word1 或者 word2 的字符串1
^A(?![word1|word2])(.*)\.css$