nginx重写url
背景在前端开发过程中,经常会遇到项目访问地址变更,这时就需要使用nginx的重写功能,对请求进行重写,让老链接访问到新的服务地址1)域名、服务器变更2)url变更3)参数变更nginx配置1、域名rewritelocation / {rewrite https://www.baidu.com permanent;}2、url rewritelocation /product {if ($uri ~
·
背景
在前端开发过程中,经常会遇到项目访问地址变更,这时就需要使用nginx的重写功能,对请求进行重写,让老链接访问到新的服务地址
1)域名、服务器变更
2)url变更
3)参数变更
nginx配置
1、域名rewrite
location / {
rewrite https://www.baidu.com permanent;
}
2、url rewrite
location /product {
if ($uri ~* "b1000") {
#访问/product/b1000,重写为/p/1000
rewrite ^/(.*)/(.*)$ /p/1000 permanent;
break;
}
#访问/product/a12,重写为/p/a12
rewrite ^/(.*)/(.*)$ /p/$2 permanent;
}
3、参数重写
更多推荐
已为社区贡献1条内容
所有评论(0)