温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

nginx proxy_pass 和 proxy_redirect

发布时间:2020-08-08 16:54:46 来源:ITPUB博客 阅读:1261 作者:forest7707 栏目:建站服务器

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了。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI