【发布时间】:2019-03-24 14:56:23
【问题描述】:
我有一个在谷歌应用引擎上运行的网站,它有一个私有的 dns。
但是每次我打开该网站时,它都会以 http 形式打开,我尝试在烧瓶上使用 before_request 装饰器将 http 更改为 https,但我得到了 too_many_redirects 错误,我也尝试使用 ProxyFix 但由于我的页面没有 X-Forwarded -Proto 作为标题,它不会重定向到正确的页面。
编辑:我忘了说我使用的是 flex 环境
配置此行为的最佳方式是什么?我在哪里可以设置此配置,如果可能,我该如何设置?
这就是我尝试重定向的方式:
@app.before_request
def before_request():
if request.endpoint in app.view_functions and request.headers.get('X-Forwarded-Proto', None) == 'http':
code = 301
return redirect(request.url.replace('http://', 'https://'), code=code)
非常感谢您的帮助!
【问题讨论】:
标签: python google-app-engine flask