在nginx中的location中的proxy_pass / 加不加的区别?

c7--01进行代理:在c7--03中:在文件中放一个index.html

[root@C7--03 html]# ls
aaa   index.html

 案例1

         location /aaa {
         proxy_pass http://192.168.2.3:81;
         }

 都不加 / 访问的上c7--03上的 html/aaa/index.html

 当前访问:http://192.168.2.1/aaa     实际访问:http://192.168.2.3/aaa/index.html

案例2

         location /aaa {
         proxy_pass http://192.168.2.3:81/;
         }

 给proxy_pass路径最后加 /  会访问到 c7--03的 html/index.html

当前访问:http://192.168.2.1/aaa      实际访问:http://192.168.2.3/html/ndex.html

案例3

         location /aaa/ {
         proxy_pass http://192.168.2.3:81/;
         }

全部加 /  和案例2结果一样

 当前访问:http://192.168.2.1/aaa/      实际访问:http://192.168.2.3/html/ndex.html

例如4

         location /aaa/ {
         proxy_pass http://192.168.2.3:81;
         }

 在location上加  / 会和案例1 一样

  当前访问:http://192.168.2.1/aaa/      实际访问:http://192.168.2.3/html/aaa/ndex.html

例如5

         location /aaa/ {
         proxy_pass http://192.168.2.3:81/aaa;
         }

 在location里面加  /   在uri路径添加aaa路径;会出现两个 / 访问页面失败   原因:因为在c7--03服务器上的html路径下的aaa路径下没有第二个aaa所有报错为什么没有显示就不知道了   

当前访问:  http://192.168.2.1/aaa    实际上访问的:http://192.168.2.3/aaa/aaa

 案例6

         location /aaa/ {
         proxy_pass http://192.168.2.3:81/aaa/;
         }

 全部加  / 会发现可以访问成功但是 有两个 /     原因:因为加了  /  就会去掉匹配前缀但是只是去掉了前缀没有去掉后面的  /  所有显示两个 /

  当前访问:http://192.168.2.1/aaa//     实际访问:http://192.168.2.3/html/aaa//ndex.html

 案例7

         location /aaa {
         proxy_pass http://192.168.2.3:81/aaa/;
         }

只给proxy_pass加 /  同146案例  但是aaa后面没有自动跟  /

  当前访问:http://192.168.2.1/aaa     实际访问:http://192.168.2.3/html/aaa/ndex.html

总结:1、4、5、6不加  /  ;会加location的路径到proxy_pass路径后面 ;而2和3、7案例加上/  后;不会把location的路径加到proxy_pass路径后面

如不加  /:1、4、5、6:proxy_pass路径+location路径=http://192.168.2.3/URI路径/location路径     #这类属于URI(相对路径)

如加 / :2、3、7:      proxy_pass路径(不加location路径)=http://192.168.2.3/URI路径/             #这类属于URL(绝对路径)

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

乘浪初心

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值