【问题标题】:Flask in production with Caddy and Waitress url_for redirect to localhostFlask 在生产中使用 Caddy 和 Waitress url_for 重定向到 localhost
【发布时间】:2020-06-19 17:14:46
【问题描述】:

我有一个在 Windows EC2 实例上运行的 Flask 服务器。

我需要使用 https 协议,所以我的设置是这样的:

  • 我有一个 Caddy 服务器
  • 我使用 Waitress 运行我的烧瓶应用程序

这是我对 Caddy 的配置:

example.com:443{
    proxy / 127.0.0.1:8080
    tls me@example.com
}

一切正常,除了在我的 application.py 文件中,当我这样做时:

return redirect(url_for('test', filename=filename))

我的网络浏览器重定向我:

_external=True 的结果相同

但是在模板页面上,例如 https://example.com/test2 如果我有一个链接 render_template( "test2.html") 渲染,则生成的 HTML 很好:https://example.com/

现在我已经在 application.py 中对我的 url 进行了硬编码,但这不是我想要保留它的方式...

【问题讨论】:

  • 你尝试过:_scheme="https" in url_for 吗?

标签: python flask wsgi caddy waitress


【解决方案1】:

我已将我的 Caddyfile 更新为此,现在它运行良好!

example.com:443 {
    proxy / 127.0.0.1:8080 { 
        header_upstream Host {host} 
        header_upstream X-Real-IP {remote} 
        header_upstream X-Forwarded-For {remote} 
        websocket 
    }
        tls me@example.com
}

This answer给了我一个提示。

This answer 帮助我构建了 Caddyfile。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-11
    • 2018-06-25
    • 2011-04-22
    • 1970-01-01
    • 2015-08-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多