使用http4s从http更改为https

使用http4s从http更改为https,http,https,http4s,Http,Https,Http4s,有没有办法使用http4s库将http服务器更改为https?()我发现自己也面临同样的问题,但我设法解决了,事情是这样的: 您需要寻找构建服务器的时机,可能是使用BlazeServerBuilder BlazeServerBuilder使用“WissLcontext(sslContext:sslContext)”方法启用SSL。因此,您只需创建一个SSLContext对象并将其传递给服务器生成器 请记住,在使用SSL证书之前,您可能必须使用Java的keytool实用工具将其存储在密钥库中

有没有办法使用http4s库将http服务器更改为https?()

我发现自己也面临同样的问题,但我设法解决了,事情是这样的:

  • 您需要寻找构建服务器的时机,可能是使用BlazeServerBuilder

  • BlazeServerBuilder使用“WissLcontext(sslContext:sslContext)”方法启用SSL。因此,您只需创建一个SSLContext对象并将其传递给服务器生成器

  • 请记住,在使用SSL证书之前,您可能必须使用Java的keytool实用工具将其存储在密钥库中。

    --

    如何使用SSL证书创建SSL上下文是另一个问题,但这里有一篇有趣的文章,介绍了从Let's Encrypt获取免费证书、将其存储在密钥库中以及从Java应用程序使用它的过程:

    下面是我用来在Scala中创建SSLContext的代码:

    val keyStorePassword: String   = your_keystore_password
    val keyManagerPassword: String = your_certificate_password
    val keyStorePath: String       = your_keystore_location
    
    val keyStore = KeyStore.getInstance(KeyStore.getDefaultType)
    
    val in = new FileInputStream(keyStorePath)
    keyStore.load(in, keyStorePassword.toCharArray)
    
    val keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm)
    keyManagerFactory.init(keyStore, keyStorePassword.toCharArray)
    
    val trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm)
    trustManagerFactory.init(keyStore)
    
    val sslContext = SSLContext.getInstance("TLS")
    sslContext.init(keyManagerFactory.getKeyManagers, trustManagerFactory.getTrustManagers, new SecureRandom())
    sslContext
    

    请提供更多详细信息示例: