栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

在nginx中的location中的proxy

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在nginx中的location中的proxy

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(绝对路径)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/599634.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号