我已经按照uwsgi的一个片段来尝试启用hsts。这是我当前的配置:
[uwsgi]
http-socket = :$(PORT)
master = true
processes = 4
die-on-term = true
module = webapp:app
memory-report = true
check-static = %v/webapp/static/
route= ^/?$ static:%v/webapp/static/pages/index.html
route-host = ^localhost:(?:[0-9]+)$ last:
route-if-not = equal:${HTTPS};on redirect-permanent:https://${HTTP_HOST}${REQUEST_URI}
route-if = equal:${HTTPS};on addheader:Strict-Transport-Security: max-age=31536000
route = .* last:
我要做的是对除localhost之外的任何内容强制执行hst。该站点在本地主机上工作,但在heroku上,对主页的请求根本不会被重定向,对静态资产的请求进入无限循环,甚至https请求也会被重定向。
编辑
问题是heroku的负载均衡器没有安全地连接到dyno。是否有基于
X-Forwarded-Proto
报头的路由方法,或基于包含协议的完整请求url(以便我可以将其与^https:
匹配)? 最佳答案
这对我有用:
route-if = equal:${HTTP_X_FORWARDED_PROTO};http redirect-permanent:https://${HTTP_HOST}${REQUEST_URI}