Back

Configuring Tomcat with HTTP2 - a dotCMS example

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

To learn more about the benefits of the HTTP2 protocol, see: https://en.wikipedia.org/wiki/HTTP/2

Code

<!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="UTF-8"/>



   <Connector port="8443"
	  protocol="org.apache.coyote.http11.Http11AprProtocol"
	  maxThreads="150" SSLEnabled="true">
	    <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol"/>
	    <SSLHostConfig honorCipherOrder="false">
	        <Certificate certificateKeyFile="/Users/xxxxxx/git/STAR_dotcms_io/dotcms.io.key"
	          certificateFile="/Users/xxxxxx/git/STAR_dotcms_io/dotcms.io.crt"/>
	    </SSLHostConfig>
	</Connector>

Have you created code you'd like to share with the dotCMS community?

Share your code Become a Contributor