【问题标题】:HTTPS request redirected to HTTPHTTPS 请求重定向到 HTTP
【发布时间】:2019-09-08 23:41:28
【问题描述】:

我在 traefik 入口后面运行 Gunicorn。 HTTP 被 traefik 重定向到 HTTPS,但由于某种原因,gunicorn 回复了一个指向 HTTP 的 301。我已经尝试了几乎所有我知道的选项,但没有找到任何解决方案。我认为它可能与 https://stackoverflow.com/a/41488430/3719845 之类的东西有关。

这是我在入口处使用的注释:

kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/frontend-entry-points: http,https
traefik.ingress.kubernetes.io/protocol: http
ingress.kubernetes.io/ssl-redirect: 'true'
traefik.frontend.rule.type: PathPrefix
ingress.kubernetes.io/custom-request-headers: 'x-forwarded-proto:https||x-forwarded-ssl:on||x-forwarded-protocol:ssl'

我不确定 x-forwarded 标头是否由 traefik 自动设置,因此我对它们进行了硬编码。

在 gunicorn 方面,我使用:

    command:
      - '/usr/local/bin/gunicorn'
    args:
      - '-b'
      - '0.0.0.0:8080'
      - '--log-level'
      - 'debug'
      - '--access-logfile'
      - '-'
      - '--error-logfile'
      - '-'
      - '--forwarded-allow-ips'
      - '0.0.0.0'
      - '--proxy-allow-from'
      - '0.0.0.0'
      - '--proxy-protocol'
      - 'myapp'

同样的事情,我一直在玩这些选项,但似乎没有任何改变。

【问题讨论】:

    标签: kubernetes gunicorn traefik traefik-ingress


    【解决方案1】:

    试试这个作为你的标题:

    ingress.kubernetes.io/ssl-proxy-headers: "X-Forwarded-Proto: https"
    ingress.kubernetes.io/ssl-redirect: "true"
    

    (这是用于 aws elb 的配置。我不知道您的具体配置)

    从那里,您可能会遇到不尊重 X-Forwarded-Proto 标头的 gunicorn 问题,并希望查看他们的文档。

    【讨论】:

    • 这适用于在 gunicorn 上添加 --forwarded-allow-ips *
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-18
    • 2015-02-02
    • 2021-07-27
    • 2014-06-30
    相关资源
    最近更新 更多