Search code examples
jettyhttp2embedded-jetty

How to configure Jetty in HTTP2 with external ssl offloading


All examples under https://github.com/eclipse/jetty.project have ssl factory in them.

In my case ssl offloading is done at nginx level with self signed cert.

What I need is just h2 connector (don't even h1) configured.


Solution

  • Setup Jetty with the h2c connector using the HTTP2CServerConnectionFactory.

    If you are using jetty-home (or the older jetty-distribution), just enable the http2c module.

    If you are using embedded-jetty, use the following rough outline for your connector.

    HttpConfiguration config = new HttpConfiguration();
    // ... configure 
    
    HTTP2CServerConnectionFactory http2c = new HTTP2CServerConnectionFactory(config);
    ServerConnector connector = new ServerConnector(this, http1, http2c);
    connector.setPort(port);
    server.addConnector(connector);