nginx proxy_pass参数配置带不带‘/’

1. proxy_pass 配置的url后面,不加'/',那么重定向后,追加location后的路径。
比如server_name: 10.9.11.225
location /proxy1/{
proxy_pass http://10.9.11.166:8540/;
}
location  /proxy2/ {
          proxy_pass http://10.9.11.166:8540/haha/;
}
如果访问 10.9.11.225/proxy1/   会代理到http://10.9.11.166:8540/
如果访问 10.9.11.225/proxy2/   会代理到http://10.9.11.166:8540/haha/

2. 如果proxy_pass配置的url后面,不加'/',那么重定向后,整个替换location后的路径。
location /proxy3/{
proxy_pass http://10.9.11.166:8540;
}
location  /proxy4/ {
          proxy_pass http://10.9.11.166:8540/haha;
}
访问http://10.9.11.225/proxy/就会被反向代理到http://10.9.11.166:8540/proxy/
访问http://10.9.11.225/proxy4/index.html就会被反向代理到http://10.9.11.166:8540/hahaindex.html

3.rewrite 参数简介

location /momo/{

  rewrite ^/momo/?(.*) /$1 break;

  proxy_pass http://front;

  ...

}

uri>>>lixiaoxuan.com/momo/test/hello? 重定向到了哪里?
是front/momo/test/hello......吗?   答案是错误的,因为有一个rewrite,这个配置又是干啥的?
基本语法: rewrite regex replacement [flag];
上下文:server, location, if
flag:break,重写后,不发起新的请求,直接往下走

匹配'/maimai/'重写后,uri变成了front/test/hello?
再根据front配置重定向到其他

 

转载于:https://www.cnblogs.com/lixiaoxuan/p/10918564.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值