我已经按照 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:
我想要做的是对除本地主机之外的任何东西强制执行 hsts。该站点在 localhost 上运行,但在 heroku 上,对主页的请求根本不会被重定向,对静态资产的请求会进入无限循环,甚至 https 请求也会被重定向。
编辑
问题是 Heroku 的负载均衡器没有安全地连接到测功机。有没有办法基于X-Forwarded-Proto
标头路由,或者基于完整的请求 url,包括协议(所以我可以匹配它^https:
)?