重定向已从 Https 降级为 Http

Redirects been downgraded from Https to Http

我们正面临一个问题,我们真的不知道它来自哪里。

我们的应用程序使用 Spring CloudSpring Oauth2Spring Boot 1.5.9。入口点是一个 API-Gateway 服务,使用 Zuul 将调用重定向到其他微服务。有一个 Authorization-server 来处理 Oauth2 授权,不能从外部访问,但可以通过 API-Gateway

它配置为对来自客户端的每个调用使用 Https,然后我们在系统内部使用 Http 在微服务之间进行通信。它位于 Apache proxy 后面,配置了使用 Https 并禁用端口 80 的证书。

我们目前遇到的问题是,来自 Spring Security 过滤器的每个重定向最终都会在浏览器中从 Https 降级为 Http,然后作为端口失败80 已禁用,无法找到该应用程序。

该应用程序以前可以运行,但现在不能运行。我们使用 docker 所以我们尝试重新部署以前的图像,但它们也不起作用。 Apache conf 也没有改变。

我们不确切知道哪个部分失败了,如果是 Apache proxy 或 Spring 配置,特别是当我们能想到的一切都已恢复到以前的工作问题时。

使用此设置,可以强制更改重定向的内容是什么?我们如何验证它? Spring Security 配置会影响这个还是更可能来自 Apache proxy?

这是我们目前的Apache config

<VirtualHost *:443>
  SSLEngine on
  SSLCertificateFile /etc/apache2/vpp-api/ssl/server-cert.pem
  SSLCertificateKeyFile /etc/apache2/vpp-api/ssl/server-key.pem

  SSLVerifyDepth 10
  SSLCACertificateFile /etc/apache2/vpp-api/ssl/cacert.pem

  <location />
    ProxyPreserveHost on
    ProxyPass http://localhost:8080/
    ProxyPassReverse http://localhost:8080/
  </location>

</VirtualHost>

我终于找到问题了。基本上是 Apache conf 中的这一行:

ProxyPreserveHost on

它正在更改 header Location,因为在我们系统内重定向的所有请求都失去了 Https 协议。在此之后发回的所有重定向都使用 Http

继续使用此配置的解决方案是手动覆盖 Apache conf 中的 Http

Header edit Location ^http://(.*)$ https://