Nginx 域名匹配、重定向
文章目录
匹配
=,精确匹配
location = / {
#规则
}
~,大小写敏感
location ~ /Example/ {
#规则
}
~*,大小写忽略
location ~* /Example/ {
#规则
}
^~,只匹配以 uri 开头
location ^~ /img/ {
#规则
}
@,nginx内部跳转
以 /img/ 开头的请求,如果链接的状态为 404。则会匹配到 @img_err 这条规则上。
location @img_err {
# 规则
}
跳转
假设下面四种情况分别用 http://127.0.0.1/test/test.html 进行访问。
location /test/ {
proxy_pass http://127.0.0.1/;
}
代理到URL:http://127.0.0.1/test.html
location /test/ {
proxy_pass http://127.0.0.1;
}
代理到URL:http://127.0.0.1/test/test.html
location /test/ {
proxy_pass http://127.0.0.1/aaa/;
}
代理到URL:http://127.0.0.1/aaa/test.html
location /test/ {
proxy_pass http://127.0.0.1/aaa;
}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论