【问题标题】:How to have a POST request on redirected servers?如何在重定向的服务器上发出 POST 请求?
【发布时间】:2019-05-30 16:12:49
【问题描述】:

我正在脚本上设置 nginx 负载平衡器。
www.loadbalancer.com/request.php =>
www.example01.com/request.php
www.example02.com/request.php
www.example03.com/request.php

eg. 我想发送一个 POST 请求,当我检查www.example.com 的 access_log 时它显示 POST 但是当我继续访问 www.example01.com 时它显示 GET 所以它不会使用我的 x-www-form-urlencoded。

我在 nginx/1.10.3 上。

www.loadbalancer.com[date] "POST /request.php HTTP/1.1" 301 185 "-" PostmanRuntime/7.4.0
www.example01.com[date] "GET /request.php HTTP/1.1" 200 45 "https://www.loadbalancer.com/request.php" PostmanRuntime/7.4.0

loadbalancer.conf

location = /request.php {<br>
  proxy_pass http://backup_servers$request_uri;<br>
  proxy_redirect http://backup_servers$request_uri https://backup_servers$request_uri;
  proxy_set_header Host $host;<br>
  proxy_set_header X-Real-IP $remote_addr;<br>
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>

  proxy_method POST;<br>

  proxy_set_header content-type "application/x-www-form-urlencoded";<br>
}

我希望方法变成 POST。

【问题讨论】:

  • 如果表单提交到不安全的 http url,它不会变成 POST。从非安全的 http url 重定向到安全的 https url。表单提交到安全 https url 时能否确认访问日志
  • 为什么要使用80端口发送post请求?当我在目标服务器上设置禁用返回 301 时,我有 404 错误,因为没有配置所有内容都在 443 端口上。

标签: php nginx server load-balancing nginx-reverse-proxy


【解决方案1】:

将您的 proxy_passproxy_redirect 更改为 https:// 网址。否则,您将在额外重定向期间丢失您的 POST 信息。代理重定向将使用您指定的 https 之前的 http 位置,这意味着它总是会先尝试 http 。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-04
    • 2013-09-02
    • 1970-01-01
    相关资源
    最近更新 更多