# Akka-HTTP server HTTPS Support

**URL:** <https://discuss.akka.io/t/akka-http-server-https-support/6082>\
**Category:** Akka HTTP\
**Tags:** akka, akka-http, java, configuration\
**Created:** [March 11, 2020, 10:28am UTC](https://discuss.akka.io/t/akka-http-server-https-support/6082 "2020-03-11T10:28:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![archie\_by](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/archie_by/32/2105_2.png) [@archie\_by](https://discuss.akka.io/u/archie_by)\
**Post date:** [March 11, 2020, 10:28am UTC](https://discuss.akka.io/t/akka-http-server-https-support/6082/1 "2020-03-11T10:28:20Z")

</div>

I found myself struggling to enable https support for our akka-http java application. The documentation page ([https://doc.akka.io/docs/akka-http/current/server-side/server-https-support.html](https://doc.akka.io/docs/akka-http/current/server-side/server-https-support.html)) should be helping, but for some reason in my case it does not.

From what I got from that page - the idea is to obtain an `HttpsConnectionContext` instance and use it as a parameter for the `http.setDefaultClientHttpsContext(...)` method call before actually doing some route binding.

What I have so far  
Code that creates an `SSLContext` from the configuration:

```auto
public static SSLContext getSslContext(String path, ActorSystem system) {
    final AkkaSSLConfig sslConfig = AkkaSSLConfig.get(system);

    final Config overrides = system.settings().config().getConfig(path);
    final Config defaults = system.settings().config().getConfig("ssl-config");

    final SSLConfigSettings config = SSLConfigFactory.parse(overrides.withFallback(defaults));

    return new ConfigSSLContextBuilder(
        new AkkaLoggerFactory(system),
        config,
        sslConfig.buildKeyManagerFactory(config),
        sslConfig.buildTrustManagerFactory(config)
    ).build();
}

```

Actual peace of configuration:

```auto
akka.ssl-config {
  trustManager = {
    stores = [
      { type: "JKS" , path: "xxx-truststore.jks", password = "xxx"}
    ]
  }
  keyManager = {
    stores = [
      { type: "JKS" , path: "xxx-keystore.jks", password = "xxx"}
    ]
  }
}

```

Using them to enable https:

```auto
final SSLContext sslContext = getSslContext("akka.ssl-config", system);
final HttpsConnectionContext httpsContext = ConnectionContext.https(sslContext);
http.setDefaultClientHttpsContext(httpsContext);

final CompletionStage<ServerBinding> binding =
    http.bindAndHandle(routeFlow, ConnectHttp.toHost("localhost",443), materializer);

```

But that actually does nothing. If I try to make some https call to the server I get the following exception:

`Illegal request, responding with status '400 Bad Request': Unsupported HTTP method: The HTTP method started with 0x16 rather than any known HTTP method. Perhaps this was an HTTPS request sent to an HTTP endpoint?`

I’m probably missing something, but I have no idea what

---

<div class="post-metadata">

**Author:** ![archie\_by](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/archie_by/32/2105_2.png) [@archie\_by](https://discuss.akka.io/u/archie_by)\
**Post date:** [March 11, 2020, 11:00am UTC](https://discuss.akka.io/t/akka-http-server-https-support/6082/2 "2020-03-11T11:00:14Z")

</div>

looks like my fault after all)  
the method to use is obviously `http.setDefaultServerHttpContext(...)` not `http.setDefaultClientHttpsContext(...)`

---

<div class="post-metadata">

**Author:** ![pranavkapoorr](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/pranavkapoorr/32/2889_2.png) [@pranavkapoorr](https://discuss.akka.io/u/pranavkapoorr)\
**Post date:** [July 24, 2022, 10:25pm UTC](https://discuss.akka.io/t/akka-http-server-https-support/6082/3 "2022-07-24T22:25:22Z")

</div>

Did you try to hit few requests with postman?

I have created similar application but when I am using Postman to send request, It’s not failing it and just letting it in.

I tried POST request as well as WSS request.

Please let me know your outcome.

---

<div class="post-metadata">

**Author:** ![pranavkapoorr](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/pranavkapoorr/32/2889_2.png) [@pranavkapoorr](https://discuss.akka.io/u/pranavkapoorr)\
**Post date:** [July 24, 2022, 10:51pm UTC](https://discuss.akka.io/t/akka-http-server-https-support/6082/5 "2022-07-24T22:51:10Z")

</div>

seem fixed by using the following

`engine.setNeedClientAuth(true);`
