我有一個使用Heroku的SSL端點在Heroku上運行的Play Framework應用程序。如何強制播放框架2以始終使用SSL?
我想僅通過SSL
提供所有頁面。
什麼是最好的方法呢?
到目前爲止,我的最好的解決辦法是使用我GlobalSettings
和路線non-SSL
請求onRouteRequest
到一個特殊的重定向處理:
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開始關閉非ssl。端口=禁用,如果這就是你要找的:http://www.playframework.com/documentation/2.2.x/ConfiguringHttps –
從Play的角度來看,我沒有使用SSL。 Heroku的負載均衡器將SSL代理爲應用程序的直接HTTP。 –
有沒有更新?我最終做了類似的事情,但我會偏好禁用http,但是我無法使其工作。 – Setheron