【发布时间】:2013-10-09 10:34:18
【问题描述】:
我有一个使用 Heroku 的 SSL 端点在 Heroku 上运行的 Play Framework 应用程序。
我想让所有页面仅通过SSL 提供。
最好的方法是什么?
到目前为止,我最好的解决方案是在我的GlobalSettings 中使用onRouteRequest 并将non-SSL 请求路由到一个特殊的重定向处理程序:
override def onRouteRequest(request: RequestHeader): Option[Handler] = {
if (Play.isProd && !request.headers.get("x-forwarded-proto").getOrElse("").contains("https")) {
Some(controllers.Secure.redirect)
} else {
super.onRouteRequest(request)
}
}
和
package controllers
import play.api.mvc._
object Secure extends Controller {
def redirect = Action { implicit request =>
MovedPermanently("https://" + request.host + request.uri)
}
}
有没有办法完全在GlobalSettings 内完成这项工作?或者更好的东西?
【问题讨论】:
-
如果您正在寻找的话,您可以从 -Dhttp.port=disabled 开始关闭非 ssl:playframework.com/documentation/2.2.x/ConfiguringHttps
-
从 Play 的角度来看,我没有使用 SSL。 Heroku 的负载均衡器正在将 SSL 代理到应用程序的直接 HTTP。
-
这方面有更新吗?我最终做了类似的事情,但我更喜欢禁用的 http,但我无法让它工作。
标签: scala ssl heroku playframework-2.0