繁体   English   中英

如何仅在开发模式下在 HTTPS 中运行 Play 框架?

[英]How can I run Play framework in HTTPS only in the dev mode?

只想在开发模式下通过 HTTPS 运行 Play Framework,我已经使用以下配置完成了:

https.port=9443
trustmanager.algorithm=JKS
keystore.file=conf/certificate.jks
keystore.password=password
certificate.password=password
application.mode=dev
%prodenv.application.mode=prod

这在我运行play run但在生产中我们运行play run --%prodenv并且我想禁用 HTTPS,因为 HTTPS 由 Nginx 处理。 我不知道如何做到这一点。 我想通过配置文件而不是通过额外的命令行参数来做到这一点,因为它违背了将我的所有应用程序配置放在application.conf文件中的目的。

一种方法是有两个 confs 文件: application.confprod.conf

application.conf保持prod.confprod.conf看起来像

include "application.conf"
https.port = myProdPort

### other params to be overwritten

在 prod 中启动您的应用程序时,您可以执行以下操作

play run -Dconfig.file=/mypath/prod.conf

sbt run -Dhttps.port=9443 -Dhttp.port=disabled

我没有使用两个配置文件,而是通过一个来实现这一点。 为了运行该应用程序,我运行play run --%dev ,这就是配置的样子。

%dev.https.port=9443
%dev.trustmanager.algorithm=JKS
%dev.keystore.file=conf/certificate.jks
%dev.keystore.password=password
%dev.certificate.password=password

与 Johan 的其他答案类似,我采用相反的方式:我的application.conf用于生产,而我只是在开发中运行dev.conf

include "application.conf"
https.port = devPort

并像这样在本地运行:

play run -Dconfig.file=dev.conf

这样您就不必更改生产服务器上的任何配置。

当您在开发模式下运行它时,您可以从您的 conf 文件中删除https.port参数并通过命令行传递它:

play run -Dhttp.port=9443

请参阅: 指定服务器地址和端口

Play 框架使用 Netty 服务器运行,您可以使用-D参数覆盖服务器配置。

sbt它可以这样做:

sbt "project pepe-grillo-server" "run -Dhttps.port=42443 -Dhttp.port=disabled"

如果您使用自定义 ssl 引擎提供程序CustomSSLEngineProvider您可以使用以下命令在 ssl 模式下运行 netty。

./sbt "-Dhttps.port=9443" "-Dplay.server.https.engineProvider=services.https.CustomSSLEngineProvider" "-Dconfig.resource=<config file> run

服务器启动并运行后,您可以卷曲端点以检查证书有效性。

curl -v https://127.0.0.1:9443

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM