我有一个 Flask 应用程序在 Nginx 服务器后面。Nginx 处理 SSL 终止和重定向到 https,所有 http 请求都被重定向。
在 Flask 中,我认为不需要知道任何这些内容,我有以下代码:
@bp.route('/', methods=['GET', 'POST'])
def index_root():
"""Assign a session tag.
"""
return redirect(url_for('main.index', tag=make_new_tag()))
@bp.route('/D/<tag>/accueil', methods=['GET', 'POST'])
def index(tag):
return render_template('index.html', title='', tag=tag)
现在我有一个问题:当有人请求
http://example.com/
时,nginx会将其301重定向到https://www.example.com/
,这是正确的。然后flask将其302重定向到http://www.example.com/D/123/accueil
,这不太好,因为nginx只会将其301重定向到https://www.example.com/D/123/accueil
(这是好的,但我更喜欢跳过这个额外的重定向)。这是某个配置问题吗?
请注意,在开发中,flask确实不考虑https是很重要的。事实上,flask根本不需要知道https的任何信息,这就是为什么我觉得有点费解的原因。
谢谢任何指导。