手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

nginx的proxy_redirect如何使用解决重定向失败

时间:2024-10-12 04:29:54

1、使用xshell工具连接上linux服务器,使用vi命令打开nginx的conf下面的nginx.conf文件,如图所示添加proxy_redirect off;则表示关闭

nginx的proxy_redirect如何使用解决重定向失败

2、为了演示效果,构造重定囿鹣分胰向页面条件,a.jsp和b.jsp两个文件,a页面重定向到b页面,注意这里使用的jsp的方式重定向,服务器返回邓咀挚垡重定向会返回Location响应头,不要使用javascript进行重定向,js的方式是在浏览器进行重定向和nginx那边设置没有关系了,看不出效果

nginx的proxy_redirect如何使用解决重定向失败

3、然后访问host/app/a.jsp,正常的话,会直接跳转到b.jsp页面

nginx的proxy_redirect如何使用解决重定向失败

4、但访问之后可以看到,浏览器地址变成了nginx反向代理的内部地址和端口了,说明没有对重定向地址进行重写,说明proxy_redirect配置不合理导致的

nginx的proxy_redirect如何使用解决重定向失败

5、错误示例已经看出来导致的问题了,下面来看下proxy_redirect就具体使用方法,和不同配置的区别,如图所示是官方文档的语法说明

nginx的proxy_redirect如何使用解决重定向失败

6、参照如图所示的方式进行proxy_redirect的配置,输入nginx -s reload重启nginx服务

nginx的proxy_redirect如何使用解决重定向失败

7、再次访问a.jsp页面,则这次可以这次重定向到b.jsp页面了,虽然是成功了,但可能你还不能完全理解。配置proxy_redirect与不配置,以及default等众多方式的区别不了解的话,可以看下面的总结对比说明

nginx的proxy_redirect如何使用解决重定向失败

8、nginx的proxy_red坡纠课柩irect用法总结:访问测试地址:hostA/app/a.jsp测试代理地址:prox烤恤鹇灭y_pass hostB:8080/test_app/;用法对比:proxy_redirect hostB:8080/ /app/跳转到:hostA/app/test_app/b.jspproxy_redirect hostB:8080/ /跳转到:hostA/test_app/b.jspproxy_redirect / /;跳转到:hostB:8080/test_app/b.jspproxy_redirect default;跳转到:hostA/app/b.jspproxy_redirect hostB:8080/test_app/ /app/;(与default等同)跳转到:hostA/app/b.jspproxy_redirect hostB:8080/test_app/ hostA/app/;跳转到:hostA/app/b.jspproxy_redirect(不加)跳转到:hostA/app/b.jspproxy_redirect off;跳转到:hostB:8080/test_app/b.jspproxy_redirect hostB:8080/test_app/ /;跳转到:hostA/b.jsp

© 手抄报圈