OpenShift解决Route Https->Http无法跳转的问题

OpenShift Haproxy

问题现象

通过Route创建的edge类型的HTTPS,后端应用使用的是HTTP服务。但在某些情况下,后端应用使用Location时,Location地址为HTTP地址。这时浏览器将因为无法访问HTTP服务而无法实现跳转。

原理

Haproxy在返回客户端时,检查返回Head,将Location地址中的HTTP替换为HTTPS,从而让浏览器获取正确的跳转链接。

解决办法

更新haproxy-config.template,为edge请求的应用添加标注判断haproxy.router.openshift.io/location-scheme,如果它为https,则将Location请求中的http替换为https。
具体配置如下:搜索 ssl_fc_alpn -i h2在其后添加如下配置

{{- if eq "https" (index $cfg.Annotaions "haproxy.router.openshift.io/location-scheme")}}
  acl check_location res.hdr(Location) -m found
  rspirep ^Location:\ http://(.*) Location:\ https://\1 if check_location
{{- end}}

示例

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  annotations:
    haproxy.router.openshift.io/location-scheme: 'https'
  labels:
    router: web-app
  name: web-app
spec:
  host: test.com
  port:
    targetPort: http
  tls:
    termination: edge
  to:
    kind: Service
    name: web-app
EOF

对于已经创建的Route可通过命令设置annotations

$ oc annotate route web-app haproxy.router.openshift.io/location-scheme="https"
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容