分享

nginx重定向post请求

 Bladexu的文库 2017-09-13

nginx重定向post请求

场景:

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

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

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

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

这里做了一个测试。

rewrite 方式:

location /testpost {

rewrite /testpost http://www./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./testpost 'PostmanRuntime/3.0.11-hotfix.2' -

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

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

location /testpost {

proxy_pass http://www./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(反向代理)来实现。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多