您好,欢迎来到五一七教育网。
搜索
您的当前位置:首页nginx重定向post请求

nginx重定向post请求

来源:五一七教育网


nginx重定向post请求

场景:

app里访问的接口地址为/service/upload

然而现在项目中实际地址为/servicev3/upload

之所以这样是开发的时候沟通不畅,没有更新为新地址,ios已经上线,无法短时间内上新版。

临时解决办法就想到用nginx的rewrite,结果发现不成功。

这里做了一个测试。

rewrite 方式:

location /testpost {

rewrite /testpost /post.php;

}

用postman发起一个post请求

192.168.10.101 - [11/Sep/2017:10:24:06 +0800] POST /testpost HTTP/1.1 302 160 - 'PostmanRuntime/3.0.11-hotfix.2' -

302跳转

192.168.10.101 - [11/Sep/2017:10:24:06 +0800] GET /post.php HTTP/1.1 200 44 /testpost 'PostmanRuntime/3.0.11-hotfix.2' -

跳转到post.php,但是请求方式变为get,这样post的数据就无法获取到。

后来查资料,需要用proxy_pass方式:

location /testpost {

proxy_pass /post.php;

}

192.168.10.101 - [11/Sep/2017:10:28:23 +0800] POST /testpost HTTP/1.1 200 74 - 'PostmanRuntime/3.0.11-hotfix.2' -

192.168.10.50 - [11/Sep/2017:10:28:23 +0800] POST/post.php HTTP/1.0 200 63 - 'PostmanRuntime/3.0.11-hotfix.2' -

这样才看到post的数据。

个人认为 rewrite(跳转) 可能不支持post重定向,需要通过proxy_pass(反向代理)来实现。

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 517ttc.cn 版权所有 赣ICP备2024042791号-8

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务