proxy_pass的匹配规则根据其后uri路径是否加/。
不建议用替换来形容,感觉很乱。
请求路径 http://localhost:80/ng/index
①uri【http://localhost:8080】后无/
其真实路径为http://localhost:8080/ng/index ,不忽略匹配路径
location /ng/ {
proxy_pass http://localhost:8080;
}
②uri【http://localhost:8080】后有/
其真实路径为http://localhost:8080/index , 忽略匹配路径
location /ng/ {
proxy_pass http://localhost:8080/;
}
请求路径 http://localhost:80/app/index.html
root和alias的区别:
①root用于不忽略匹配路径, uri路径【F:/nginx/static/】 其后有无/ 都一样
真实路径为F:/nginx/static/app/index.html
location /app/ {
root F:/nginx/static/;
index index.html index.htm;
}
②alias用于忽略匹配路径,uri路径其后必须有 /
真实路径为F:/nginx/static/index.html
location /app/ {
alias F:/nginx/static/;
index index.html index.htm;
}
注意:
匹配路径为/,其优先级低于其它匹配路径