首页 技术 正文
技术 2022年11月15日
0 收藏 510 点赞 2,806 浏览 1069 个字

proxy_pass:充当代理服务器,转发请求
proxy_redirect:修改301或者302转发过程中的Location。默认值为proxy_redirect default。

例:
location / {
              proxy_pass http://192.168.8.46:8080/; #/结尾
              #proxy_redirect default #此为默认值,加不加都一样。
         }
这样代理到其它机器的8080端口,访问的时候都没问题,
Location: http://192.168.8.46/haha4/,浏览器的url地址栏也是http://192.168.8.46/haha4/

若:
location / {
              proxy_pass http://192.168.8.46:8080;#去掉/
              proxy_redirect off #修改默认值default为off
         }
如果去掉最后的/以后,curl -I http://192.168.8.46/haha4 访问
Location: http://192.168.8.46:8080/haha4/
浏览器访问显示的地址栏为http://192.168.8.46:8080/haha4/,(如果还是之前的,需要先删缓存)
可以看到,真实的Location地址全部暴露出来的,这个时候就需要使用proxy_redirect修改这个Location
配置如下:
location / {
              proxy_pass http://192.168.8.46:8080;
             proxy_redirect http://192.168.8.46:8080/haha4/ http://192.168.8.46/haha4/;
         }
这样,就能修改Location的地址,Location: http://192.168.8.46/haha4/,在浏览器里也是如此,就不会暴露端口号等信息,
当然,你还可以把Location弄到其它网站上去,例如
proxy_redirect http://192.168.8.46:8080/haha4/ http://www.douban.com/;
然后浏览器就跳过去了。

总结:
一切幕后黑手就是
 proxy_pass http://192.168.8.46:8080; 不加/结尾,只要把/加上,proxy_redirect 用默认值就OK了。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,031
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,861