ProxyPassReverse 在重定向时不保持正确的协议

ProxyPassReverse does not keep correct protocol while redirecting

我已经设置了一个 Virtuoso 服务器,它使用内容协商来提供关联数据。服务器通过反向代理 Apache 服务器提供服务,可以使用 httphttps.

查询
http://public.server.org/myapp      --> http://private.local.domain:1234/
https://public.server.org/myapp     --> http://private.local.domain:1234/

Virtuoso 服务器随后执行内容协商并重定向到 /describe?...

我通过http访问public服务器没有问题。发生重定向并检索内容。

但是,当我通过 https 访问 public 服务器时,重定向将我发送到 http://public.server.org/describe?...(即 HTTP,而不是 HTTPS) .

我希望被重定向到 https://public.server.org/describe?...(使用与原始查询相同的协议)。

我的配置是:

<VirtualHost xxx.yyy.zzz.ttt:80>
  ServerName public.server.org
  ProxyPass /myapp              http://localhost:8890/myapp
  ProxyPassReverse /myapp       http://localhost:8890/myapp

  ProxyRequests Off

  <Location /describe>
    ProxyPass               http://localhost:8890/describe
    ProxyPassReverse        /describe
  </Location>

</VirtualHost>

<VirtualHost xxx.yyy.zzz.ttt:443>
  ServerName public.server.org
  ProxyPass /myapp              http://localhost:8890/myapp
  ProxyPassReverse /myapp       http://localhost:8890/myapp

  ProxyRequests Off

  <Location /describe>
    ProxyPass               http://localhost:8890/describe
    ProxyPassReverse        /describe
  </Location>

</VirtualHost>

apache 是否可以正确反转代理以在重定向时保持原始查询协议?

使用 dumpio 和 Apache 错误日志进行调试后,我想我找到了问题所在。

发生了什么事?

首先,我的配置不正确。在另一个我没有在这里转录的地方,我有一个激活的 ProxyPreserveHost On 指令。因此,配置工作但出于错误的原因。

Apache 保留主机,而 Virtuoso 使用此主机。因此,当发送重定向到 /describe... 时,Virtuoso 重定向到 http://public.server.org/describe... 而不是我预期的 http://localhost:8890/describe...

因此,重定向没有被 ProxyPassReverse 指令捕获,而是原封不动地传递给客户端(它起作用了)。问题是无论原始查询方案如何,重定向总是通过 http 完成。

解决方案

我决定放弃 ProxyPreserveHost On 指令并依赖正确的 ProxyPassReverse 指令。

由于未知原因,我无法找出 Location 中的正确设置,因此我使用了设置:

<VirtualHost xxx.yyy.zzz.ttt:443>
  ServerName public.server.org
  ProxyPass /myapp              http://localhost:8890/myapp
  ProxyPassReverse /myapp       http://localhost:8890/myapp

  ProxyRequests Off
  ProxyPreserveHost Off # To avoid problems if it is set On elsewhere.

  ProxyPass /describe http://localhost:8890/describe
  ProxyPassReverse /describe http://localhost:8890/describe
</VirtualHost>

注意: 我只更改了 https 设置,因为 http 设置以某种方式起作用(因此 http virtualhost 仍然使用 ProxyPreserveHost On 而没有 ProxyPassReverse