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.
By default Tomcat will ignore all trailer headers when processing HTTP/2 connections. For a header to be processed, it must be added to this comma-separated list of header names. InitialWindowSize: Controls the initial size of the flow control window for streams that Tomcat advertises to clients. 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.
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:
2 4 | <Connector port='8443'protocol='HTTP/1.1'SSLEnabled='true' clientAuth='false'sslProtocol='TLS' keystoreFile='/Users/Khanh/Documents/tomcat_https' |
Now, for HTTP/2 support, we will add a child tag named UpgradeProtocol inside the Connector tag with the following content:
![Http2 Http2](/uploads/1/1/8/9/118960249/665578395.png)
2 4 6 | <Connector port='8443'protocol='HTTP/1.1'SSLEnabled='true' clientAuth='false'sslProtocol='TLS' keystoreFile='/Users/Khanh/Documents/tomcat_https' <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:
Note the localhost line in the picture, you will see the protocol is h2, which means HTTP/2.
Description
dotCMS 5.0 ships with Tomcat 8.5 which supports the HTTP2 protocol. HTTP2 is a modern version of HTTP that can combine multiple requests into a single request (among other benefits), greatly increasing client performance when accessing sites. If you are interested in trying to run dotCMS with HTTP2 enabled there are a few things you will need. First off, HTTP2 requires SSL and will not work without it, so you will need a valid certificate file and key. Second, if you are running tomcat without a proxy server or load balancer in front, you will need the APR library installed, which allows tomcat access to system native (non-java) libraries for better performance. You will need to
apt-get apr
or yum -i apr
or brew install apr
in order to get this running correctly. Once you do this, hit your site with https and check out your browsers developers tools to insure that you are seeing the connections using HTTP2. Your network connections should look something like the attached image.And below that is the snippet of code that activates HTTP2 in your server.xml
Http2 Tomcat Free
To learn more about the benefits of the HTTP2 protocol, see: https://en.wikipedia.org/wiki/HTTP/2