Http2 Tomcat

Posted on  by admin

Early users of HTTP/2, according to one of the main Tomcat developers Mark Thomas, reported improvement of up to 20% in page speed due to its benefits like multiplexing, header compression and server push (servlet 4.0 API needed). HTTP/2 is now the official RFC 7540, and it’s about time to deploy your website on HTTP/2, to get the numerous benefits that HTTP/2 brings. A very typical deployment is to have Apache (or Nginx) working as a reverse proxy to a Servlet Container such as Jetty or Tomcat.

From version 9 onwards, Tomcat has support for HTTP/2 but not the default. Wanting to work with HTTP/2 with Tomcat, we must have some adjustments in its configuration. In this tutorial, I will guide you.

First of all, you have to make sure that you are using Java 9 or above.

Because of only Java 9 and above supporting for Application-Layer Protocol Negotiation (ALPN). ALPN is a Transport Layer Security extension, which allows Tomcat to choose the version of the HTTP protocol that it will work with.

Currently, I have installed Java 9:

The second step we need to do is modify the server.xml file located in the conf directory of Tomcat.

The definition of HTTP/2 is not required to use a secure connection, but browsers implement it with a secure connection, so we will configure HTTP/2 support for Tomcat with HTTPS protocol.

In the previous tutorial, I have shown you how to configure HTTPS for Tomcat, the content of the Tomcat Connector for HTTPS is as follows:

Tomcat http2 configuration
<Connector port='8443'protocol='HTTP/1.1'SSLEnabled='true'
<UpgradeProtocol className='org.apache.coyote.http2.Http2Protocol'/>

That’s all we need.

To check the results, just visit https://localhost:8443/. If you are using Chrome, right click on the site, select Inspect, then select the Network tab. Refresh the site, you will see the results as follows:

Tomcat Http2 Configuration

Note the localhost line in the picture, you will see the protocol is h2, which means HTTP/2.

Spring Cloud Http 2

>On Thu, Mar 30, 2017 at 9:07 PM, Mark Thomas <[hidden email]> wrote:
>> On 30/03/17 18:02, Laurent Perez wrote:
>> > Hi
>> >
>> > I managed to run the servlets/serverpush/simpleimage HTTP/2 push
>> > from Tomcat 9 trunk with the SSL Http11AprProtocol connnector and
>> > <UpgradeProtocol
>> > className='org.apache.coyote.http2.Http2Protocol'/>.
>> >
>> > Now I would like to enable HTTP/2 but without SSL : my certificates
>> > either hosted under my load balancer or Apache itself, and I do not
>> > SSL between mod_proxy and Tomcat.
>> >
>> > But org.apache.coyote.AbstractProcessor#isPushSupported then
>> > as if the UpgradeProtocol did not fire.
>> >
>> > Is it possible to enable HTTP/2 with no SSL connector ?
>> Yes. You need to add the <UpgradeProtocol ... /> block to an HTTP
>> connector. You should see in the start-up log that h2c is enabled via
>> HTTP Upgrade.
>> Mark
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]