我需要将POST数据保存到不同的URL
重写有效但后期数据丢失
需要将数据从user_info.PHP发布到userhistory
location ~ user_info.PHP {
rewrite ^/.* http://testing.com/userhistory permanent;
}
数据丢失了.我该如何保存数据?
解决方法:
基本上,您希望使用301 Moved Permanently重定向自动重定向POST请求.
然而. HTTP Specifications特别禁止此类重定向,其中规定:
If the 301 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued.
规格还注意到:
When automatically redirecting a POST request after receiving a 301 status code, some existing HTTP/1.0 user agents will erroneously change it into a GET request.
我相信第二种情况可能是正在发生的事情,虽然目标服务器期待POST数据,但它正在接收GET数据.
你的选择是:
A.更改代码以使用GET数据或更好地使用POST和GET. I.E.,寻找POST,如果没有,请尝试GET等价物.
B.尝试通过使用Spec来确保代码接收POST数据.
您可以通过使用proxy_pass指令来代替处理请求来实现选择B.
像这样的东西:
location ~ user_info.PHP {
proxy_pass http://testing.com/userhistory;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。