场景:
app里访问的接口地址为/service/upload
然而现在项目中实际地址为/servicev3/upload
之所以这样是开发的时候沟通不畅,没有更新为新地址,ios已经上线,无法短时间内上新版。
临时解决办法就想到用nginx的rewrite,结果发现不成功。
这里做了一个测试。
rewrite 方式:
location /testpost { rewrite /testpost http://www.test.org/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 http://www.test.org/testpost "PostmanRuntime/3.0.11-hotfix.2" -
跳转到post.php,但是请求方式变为get,这样post的数据就无法获取到。
后来查资料,需要用proxy_pass方式:
location /testpost { proxy_pass http://www.test.org/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(反向代理)来实现。
原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/3868.html