[英]How to config PlayFramework2 to support SSL?
我已经阅读了如何配置playframework服务器以支持ssl ,我也试图关注http://www.playframework.org/documentation/1.1.1/releasenotes-1.1#https但它对我不起作用
非常感谢〜
我阅读了Play1的文档,因为我无法找到有关https的Play2的更新信息。
在application.conf中,我添加了以下行:
https.port=9443
certificate.key.file=conf/host.key
certificate.file=conf/host.cert
我在播放控制台中键入run
,并尝试通过https://localhost:9443
访问服务器,浏览器超时,控制台输出中没有任何记录
它不适用于您正在采取的方法。 您错误地将1.x分支的发行说明与2.x分支一起发布。
在1.x分支中 ,它是可能的。 发行说明就足够了,它们对我有用。
对于2.1+分支 ,请参阅@Christina的评论。 2.1中添加了支持,讨论线程提供了详细信息。
引用James Roper的回应
在开发模式下,它非常简单,只需:
JAVA_OPTS = -Dhttps.port = 9443播放
Play会生成一个私钥和自签名证书,显然你的浏览器会对一个大的红色警告不屑一顾。 它将为每次后续的Play运行重用生成的自签名证书,因此您应该只获得一次浏览器错误。 显然,这个自签名证书可能不是你想要的。 另外需要注意的是,自签名证书生成仅适用于使用Sun安全库的JVM(例如Oracle和OpenJDK,但最值得注意的不是IBM J9)。 在不使用这些JVM的JVM上,当它尝试生成证书时,您将获得NoClassDefFoundError。
在prod中(此配置也适用于dev),您的配置方式与通常在Java中通过系统属性配置SSL的方式相同。 这是一个总结:
https.port - 应该使用的端口
https.keyStore - 包含私钥和证书的密钥库的路径(如果未提供)会为您生成密钥库
https.keyStoreType - 密钥库类型,默认为“JKS”
https.keyStorePassword - 密码,默认为“”
https.keyStoreAlgorithm - 密钥存储算法,默认为平台默认算法
https.trustStore - 此功能尚未完全实现,目前它将始终使用JDK信任存储来验证客户端证书(您当然可以自行配置),无论您是否为此提供值,除非您指定“ noCA“,在这种情况下,它将使用信任存储,信任所有证书而不进行验证或验证,这对于使用webid客户端证书验证很有用。
对于2.0分支 ,你必须放置另一个服务器,即apache / nginx / other监听https并转发请求以在http中播放。
有关设置前端服务器的说明,请访问http://www.playframework.org/documentation/2.0.1/HTTPServer
因此,在端口上运行播放服务器。 将domain.com的apache转发请求发送到127.0.0.1:9443。
示例apache配置
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName example.com
ServerAlias *.example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
ProxyPreserveHost On
# ProxyPass /excluded !
ProxyPass / http://127.0.0.1:9000/
ProxyPassReverse / http://127.0.0.1:9000/
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
# Certificate Authority (CA):
# Set the CA certificate verification path where to find CA
# certificates for client authentication or alternatively one
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>
希望能帮助到你。
设置当前版本的Play(2.2.x)的文档位于: http : //www.playframework.com/documentation/2.2.x/ConfiguringHttps
这对于本地测试https非常有用:
activator "run -Dhttps.port=9005"
然后将浏览器指向https://localhost:9005
。
我们做的一件事是使用AWS ELB来处理我们的SSL,然后使用播放过滤器设置SSL转发(HTTP - > HTTPS)。 主要的好处是,从您的服务器上获取SSL负载,您不必在游戏前运行Apache或Nginx(正如某些解决方案所指出的那样)。
你可以在这里看到我的答案: https : //stackoverflow.com/a/23646948/690164
我还在我的博客中写了更多关于它的内容: http : //www.mentful.com/2014/05/25/play-framework-filter-for-aws-elastic-load-balancer-forward-http-to- HTTPS /
我正在使用securesocial 3.0.3M。 组
securesocial.ssl = true
在securesocial.conf中你应该很高兴。 然后重启你的sbt或激活器
JAVA_OPTS=-Dhttps.port=9443 activator run
转到localhost:9443
请享用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.