【问题标题】:PUT request gets converted to GET request by Apache ProxyPassApache ProxyPass 将 PUT 请求转换为 GET 请求
【发布时间】:2021-12-06 22:16:45
【问题描述】:

我正在编写一个在我的服务器上本地运行的 REST API (nodejs/express)(监听端口 3000);我有一个现有的 Apache 服务器设置,我想将其配置为将 api 调用重新路由到节点实例。以下是我当前使用 ProxyPass 的 Apache 配置:

<VirtualHost _default_:80>
  DocumentRoot "/opt/bitnami/apache2/htdocs"
  <Directory "/opt/bitnami/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    <IfVersion < 2.3 >
      Order allow,deny
      Allow from all
    </IfVersion>
    <IfVersion >= 2.3 >
      Require all granted
    </IfVersion>
  </Directory>

  # Error Documents
  ErrorDocument 503 /503.html

  # Bitnami applications installed with a prefix URL (default)
  Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf"
  ProxyPreserveHost On
  ProxyPass /api http://localhost:3000
  ProxyPassReverse /api http://localhost:3000
</VirtualHost>

我遇到的问题是,当 PUT 和 POST 请求从 Apache 传递到 Node 时,它​​们会被转换为 GET 请求;我最初并不认为它是this issue,因为我根本没有向客户端发送重定向代码,但我没有更好的猜测。之前有没有人见过这个问题 // 有办法强制请求在通过时保持其类型?

【问题讨论】:

    标签: apache http proxypass web-development-server


    【解决方案1】:

    我刚刚遇到了这个问题,因为 POST 被转换为 GET!

    答案对你来说太晚了,但它可能会帮助像我这样陷入这个问题的人。

    这是我文件中脚本的相关部分

    代理通行证http://127.0.0.1:NODE_APP_PORT/ ProxyPassReverse http://127.0.0.1:NODE_APP_PORT/

    把我逼疯了!尝试了stackoverflow中提到的几种解决方案

    #       Handle node REST API
    #        RewriteCond %{REQUEST_URI} /redirect_directory/ [NC]
    #        RewriteRule /redirect_directory/(.*) http://127.0.0.1:NODE_APP_PORT/$1?%{QUERY_STRING} [R=307] [P,L]
    #       proxyPassReverse /noderestshop/ http://127.0.0.1:NODE_APP_PORT
    

    您使用 307 重定向代码而不是默认的 301。但没有任何效果!

    出了什么问题?

    好吧,我使用的是 POSTMAN! Postman 版本 8 使用 http 发送我的帖子请求,而没有在 url 行中明确说明。我的 /etc/apache2/sites-enabled/ 中对应虚拟主机的配置文件 (.cof) 正在使用以下方法将其转换为 https 请求:

    #       Handdle redirection of http to https
            RewriteCond %{SERVER_NAME} =spinelli.io [OR]
            RewriteCond %{SERVER_NAME} =www.spinelli.io
            RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    

    到 https 的转换就是将 POST 请求变为 GET 的原因。从安全的角度来看,这是有道理的!您只是不要将不安全的 POST 请求传递到您的 https!

    我将邮递员 url 行中的请求更改为 https:// 和 ALBRICIAS!成功了!

    【讨论】:

      猜你喜欢
      • 2020-01-12
      • 1970-01-01
      • 2015-10-26
      • 1970-01-01
      • 2018-11-22
      • 2017-12-17
      • 2018-01-26
      • 1970-01-01
      • 2020-08-03
      相关资源
      最近更新 更多