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