【问题标题】:How to configure webapp2 routes to run with HTTPS scheme in production but not in development?如何配置 webapp2 路由以在生产中使用 HTTPS 方案运行,但在开发中不运行?
【发布时间】:2016-12-12 20:21:20
【问题描述】:

我有一个在 App-Engine 上运行的 webapp2 WSGI 应用程序。当应用程序在生产环境中运行时,如何使用 HTTPS 方案配置其路由,但如果它在开发环境中运行,则应使用 HTTP 方案?

编辑:按照建议,我添加了一个指向 webapp2 路由方案的链接

http://webapp2.readthedocs.io/en/latest/guide/routing.html#restricting-uri-schemes

【问题讨论】:

  • 您希望在生产环境中强制使用 https 吗?

标签: google-app-engine webapp2 google-app-engine-python


【解决方案1】:

你可以简单地做这样的事情:

scheme = 'http' if os.environ.get('SERVER_SOFTWARE').startswith('Development') else 'https'

webapp2.Route(..., schemes=[scheme])

【讨论】:

  • 这不是应用程序向自身发出请求的情况。如果我将方案设置为 https,则应用程序在开发环境中返回 404。我必须手动删除 URL 的方案,然后记得在将其部署到生产之前将其放回原处。
  • 你指的是这些方案吗? webapp2.readthedocs.io/en/latest/guide/…
【解决方案2】:

您只需在应用的 app.yaml 中启用 https,如下所示:

- url: .*
  script: main.app
  secure: always

然后您将在 appengine 上获得 https,但 devapp_server 仍将在 http 上提供所有内容

【讨论】:

    猜你喜欢
    • 2019-10-14
    • 2016-10-19
    • 1970-01-01
    • 2023-01-11
    • 2020-06-08
    • 1970-01-01
    • 1970-01-01
    • 2013-02-12
    • 2023-03-27
    相关资源
    最近更新 更多