ingress-gce (GKE) 前的 Apache 反向代理

Apache reverse proxy in front of an ingress-gce (GKE)

我正在尝试克服从 HTTP 到 HTTPS 的重定向流量的入口 gce 限制。

所以,最简单的配置是使用 Apache2 的反向代理,但对我不起作用,这个 apache 在我的 kubernetes 集群之外的另一个虚拟机中,我只想 "proxy" 流量所以我可以操纵请求,重定向到 https 等

我需要这个特定的解决方案才能工作,因为此时我无法配置 nginx ingress,必须使用这个 GCE ingress

我的 ingress yaml 配置是:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    kubernetes.io/ingress.global-static-ip-name: my-reserved-address
    kubernetes.io/ingress.allow-http: "false"
spec:
  tls:
  - hosts:
    - mycustom.domain.com
    secretName: mydomain-com-certificate
  rules:
  - host: mycustom.domain.com
    http:
      paths:
      - path: /*
        backend:
          serviceName: tomcat-service
          servicePort: 80
      - path: /app/*
        backend:
          serviceName: spring-boot-app-service
          servicePort: 80

我的 apache 虚拟主机配置是:

<VirtualHost *:80>
        ServerName myother.domain.com
        Redirect permanent / https://myother.domain.com/
</VirtualHost>

<VirtualHost *:443>
        ServerName myother.domain.com

        ProxyPreserveHost On
        ProxyRequests On
        ProxyPass / https://mycustom.domain.com/
        ProxyPassReverse / https://mycustom.domain.com/

        SSLEngine on
        SSLProxyEngine on
        SSLProtocol All -SSLv2 -SSLv3
        SSLCipherSuite ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:!RC4:+HIGH:+MEDIUM
        SSLCertificateKeyFile /etc/ssl/domain.com/domain.com-privatekey-nopass.pem
        SSLCertificateFile /etc/ssl/domain.com/domain.com.crt
        SSLCACertificateFile /etc/ssl/domain.com/IntermediateCA.crt
</VirtualHost>

每块拼图都按预期独立运行,我的意思是,如果我执行以下任一操作

A) https://mycustom.domain.com/tomcat_context 
B) https://mycustom.domain.com/app/hello

我得到了想要的结果,A) 我得到了我的网页,B) 我从我的应用程序得到了一个简单的响应

但是,当我使用代理时 http://myother.domain.com/tomcat_context 我可以看到它如何转换为 但我总是得到一个文本来自集群的响应,总是

default backend - 404

我也在检查 Apache2 日志,我可以看到 apache 如何在内部进行正确的调用

[Wed May 22 18:39:40.757619 2019] [proxy:debug] [pid 14196:tid 140335314564864] proxy_util.c(2213): [client xxx.xxx.xxx.xxx:52636] AH00944: connecting https://mycustom.domain.com/tomcat_context to mycustom.domain.com:443

如果所有部分都正常工作,我无法找到为什么会发生这种情况的解释,归根结底,我的 ingress-gce 就像我的 apache 代理的外部服务,它应该已经在工作了。

此外,入口和 apache 这两种配置都配置了 SSL,并且它们的证书完全相同,因为它们都在同一域 运行

任何帮助将不胜感激

入口控制器没有 myother.domain.com 的处理程序,因此生成 404。

您需要为 myother.domain.com 设置额外的 Ingress 主机,或者转 ProxyPreserveHost Off 以便代理从 ProxyPass 配置发送 mycustom.domain.com 主机名。

tomcat 应用程序如何使用 Host header 通常决定您需要通过代理映射 header 的方式。