Configure Tomcat support HTTP/2

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:

Configure Tomcat support HTTP/2

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:

Now, for HTTP/2 support, we will add a child tag named UpgradeProtocol inside the Connector tag with the following content:

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:

Configure Tomcat support HTTP/2

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

Đánh giá bài viết
Chia sẽ bài viết này ...Share on Facebook
0Tweet about this on Twitter
Share on LinkedIn

2 thoughts on “Configure Tomcat support HTTP/2

  1. Avatar

    This is my tomcat configuration. Am still getting only http/1.1 while checking in chrome. Please let me know if you find something wrong with my tomcat config:

    Thanks in advance

Add Comment