apache - 当 X-Forwarded-Proto 为 http 时取消设置 HTTPS 环境变量

标签 apache ssl google-compute-engine google-cloud-platform mod-ssl

我在我的 Google Cloud Platform HTTP 负载均衡器上设置了端点终止设置,并将 HTTPS 设置为与我的后端通信的协议(protocol)。

这意味着所有的请求,无论是HTTP还是HTTPS,都是HTTPS到apache。问题是 HTTPS 环境变量被设置为 on 即使 X-Forwarded-Proto 被设置为 http

我所有的研究和测试只指向相反的情况(当 X-Forwarded-Proto 时,将 HTTPS 设置为 on >https 通过 SetEnvIf X-Forwarded-Proto https HTTPS=on 规则)。

但是,X-Forwarded-Protohttp 时,我需要一些东西来取消设置 HTTPS/p>

我试过设置 SSLOptions -StdEnvVars 以及 SetEnvIfSetEnvUnsetEnv 的许多组合>。通过 mod_rewrite 设置它对我来说不是一个选项(我不知道它是否会起作用)。关于关闭 StdEnvVars 的一个有趣的注意事项是,即使它关闭,所有与 SSL 相关的变量都消失了,除了 HTTPS 并且我可以确认没有其他任何设置它在任何我的配置文件。

编辑:

我在我的服务器配置、虚拟主机和 htaccess 中尝试过的一些指令示例:

SetEnvIf X-Forwarded-Proto http HTTPS=Off
SetEnvIf X-Forwarded-Proto http HTTPS=0
SetEnvIf X-Forwarded-Proto http !HTTPS
SetEnv HTTPS Off
SetEnv HTTPS 0
SetEnv HTTPS
UnsetEnv HTTPS

将这些指令与其他变量一起使用,包括像 foo 这样的测试工作得很好。

最佳答案

Using these directives with other variables, including tests like foo works just fine.

首先只是一个想法(如果有人有更好的想法,很乐意收回)

Target proxies

Target proxies terminate HTTP(S) connections from clients, and are referenced by one or more global forwarding rules and route the incoming requests to a URL map.

The proxies set HTTP request/response headers as follows:

  • Via: 1.1 google (requests and responses)
  • X-Forwarded-Proto: [http | https] (requests only)
  • X-Forwarded-For: <client IP(s)>, <global forwarding rule external IP> (requests only) Can be a comma-separated list of IP addresses depending on the X-Forwarded-For entries appended by the intermediaries the client is traveling through. The first element in the section shows the origin address.

问题是这是在哪里设置的。如果在 apache 配置文件中,您可以只更改配置。如果设置在其他地方,则需要找出位置。

The TargetHttpsProxies resource也没有列出任何改变它的方法。那么,您发布导致上述行为的配置文件如何?

关于apache - 当 X-Forwarded-Proto 为 http 时取消设置 HTTPS 环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38275934/

相关文章:

php - UTF-8贯穿始终

google-app-engine - 将 Godaddy 的 SSL 证书添加到 Google App Engine

apache - 查看时将 http url 添加到 https url

php - Apache 没有从 XAMPP 控制面板运行(错误 : Apache shutdown unexpectedly. 这可能是由于端口被阻塞)

apache - 使用参数和 php 查询重写 URL

php - 如何检查你的代码环境是在 Windows 上还是在 Linux 或其他操作系统上

ruby-on-rails - 为什么我的 Rails 应用程序中会出现使用 force_ssl 的无限重定向循环?

node.js - 如何移植 Google Compute Engine 实例?

node.js - 我应该向防火墙上的 Google 负载均衡器向我的实例组开放哪些 GCE IP?

kubernetes - 如何在GCE上的容器内使用gsutil从存储桶中复制文件