码迷,mamicode.com
首页 > 其他好文 > 详细

nginx 之proxy_pass

时间:2020-03-01 19:59:10      阅读:58      评论:0      收藏:0      [点我收藏+]

标签:检查   文件   lap   代理   而不是   -o   line   一个   pass   

在nginx中配置proxy_pass代理转发时,如果在proxy_pass后面加不加路径是有很大区别的,具体情况我们来做几个测试

 

proxy_pass 后面不带路径

技术图片
    location /test {
         proxy_pass http://192.168.1.8;
    }
View Code

访问http://www.kzf.com/test/... 代理转发后URL为http://192.168.1.8/test/..。实际转发后用代理的地址+客户端的uri 来转发的。

 

proxy_pass 后面加“/”

技术图片
    location /test {
         proxy_pass http://192.168.1.8/;
    }
View Code

访问http://www.kzf.com/test/a.html 代理转发后URL为http://192.168.1.8//a.html。多了一个/,是因为去掉了location中的路径/test,然奇一proxy中的/作为根路径+客户端URI中去掉/test的部分。去掉的是location 中的uri 而不是客户端请求中的uri,例如客户端请求为http://www.kzf.com/test/asdf/a.html 那么转发后的请求的uri 为//asdf/a.html 而不是/a.html。

 

proxy_pass 后面是一个非根路径

技术图片
    location  /test {
         proxy_pass http://192.168.1.8/asdf;
    }
View Code

此情况与后面是“/”访问效果一样,实际就是proxy 后面的uri 替换location中的uri再加上客户端uri去掉localtionuri 的部分。另外proxy_pass 后面的uri 例如/asdf 后面加不加"/"都是一样的,但是有些文章却说不加/ 就是另一种情况,例如访问/http://www.kzf.com/test/a.html

转发后为/http://www.kzf.com/asdfa.html 但是实际测试中与加/一样都为/http://www.kzf.com/asdf/.a.html

 

注意:

当location为正则表达式时,proxy_pass 不能包含URI部分。否则检查配置文件的时候会报错。

 

nginx 之proxy_pass

标签:检查   文件   lap   代理   而不是   -o   line   一个   pass   

原文地址:https://www.cnblogs.com/fanggege/p/12391424.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!