nginx的root,alias以及proxy_pass

1、root和alias

root:root指定的目录是上级目录,path匹配的整个路径会追加,即root+path;

alias:alias指定的目录必须带/,path匹配后面的内容会在alias指定的目录下查找,即alias+匹配到path路径后面的部分。

例:

location /www/ {

root /home/data;

}

访问路径:http://www.abc.com/www/a.html,实际上是访问/home/data/www/a.html。

location /www/ {

alias /home/data;

}

访问路径:http://www.abc.com/www/a.html,实际上是访问/home/data/a.html。

2、proxy_pass的斜杠问题

1)path没有斜杠

location /api1 { proxy_pass http://localhost:8080; }

# http://localhost/api1/xxx -> http://localhost:8080/api1/xxx

location /api2 { proxy_pass http://localhost:8080/; }

# http://localhost/api2/xxx -> http://localhost:8080/xxx

location /api5 { proxy_pass http://localhost:8080/haha; }

# http://localhost/api5/xxx -> http://localhost:8080/haha/xxx,请注意这里的这里的双斜线。

2)path有斜杠

location /api1/ { proxy_pass http://localhost:8080; }

# http://localhost/api1/xxx -> http://localhost:8080/api1/xxx

location /api2/ { proxy_pass http://localhost:8080/; }

# http://localhost/api2/xxx -> http://localhost:8080/xxx

location /api5/ { proxy_pass http://localhost:8080/haha; }

# http://localhost/api5/xxx -> http://localhost:8080/hahaxxx,请注意这里的haha和xxx之间没有斜杠。

总结

path有无斜杠无影响,主要看proxy_pass有没有斜杠。proxy_pass没有的话,proxy_pass+path;有的话(包括端口和上下文都是一样的),proxy_pass+匹配到path路径后面的部分。

转载于:https://blog.csdn.net/lizzehqs/article/details/123661065 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值