Now that HTTP/2 is a published standard (RFC 7540) and Jetty-9.3.0 has been released with HTTP/2.0, It’s time to start running this new protocol in your deployments. So let’s look at how you can run HTTP/2 on Google Compute Engine!

Selecting an Google Compute Image

The main requirement of a image to use is that it can run Java-8, which is pretty much any recent image and I’ve used the ubuntu-1504-vivid-v20150616a stock image provided by Google. Provision an image of this following googles documentation, then login to that image with SSH.

Installing Jetty

Jetty 9.3 is not currently available as deb, so it is simplest to download and install directly it in /opt:

$ cd /opt
$ sudo curl | tar xfz -
$ export JETTY_HOME=/opt/jetty-distribution-9.3.0.v20150612

You can now make a base directory to configure a jetty instance:

$ mkdir $HOME/demo
$ cd $HOME/demo
$ java -jar $JETTY_HOME/start.jar --add-to-startd=http,https,deploy

This enables a HTTP connector on port 8080 and a HTTPS connector on port 8443.  To access remotely on the standard ports, you need to add some redirections:

$ sudo /sbin/iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
$ sudo /sbin/iptables -t nat -I PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8443

These iptables commands should be put into /etc/rc.local (or similar) to persist over restarts of the virtual machine.

Enabling HTTP/2

Unfortunately the normal steps to enable HTTP/2 on jetty will fail on Google computer engine with the following error:

org.eclipse.jetty.start.graph.GraphException: Missing referenced dependency: alpn-impl/alpn-1.8.0_45-internal

This is because the Google image is not using a standard release of java, but rather an internally modified one. Because HTTP/2 requires ALPN support to be added to the boot path of the JVM, the jetty distribution is unable to do this by default for this JVM.  However, it is a trivial matter to make a module for the internal JVM, in the demo directory:

$ mkdir -p modules/alpn-impl
$ cp $JETTY_HOME/modules/alpn-impl/alpn-1.8.0_45.mod modules/alpn-impl/alpn-1.8.0_45-internal.mod

The normal command to enable HTTP/2 can now be run and the server started:

$ java -jar $JETTY_HOME/start.jar --add-to-startd=http2
$ java -jar $JETTY_HOME/start.jar

The server is now running and you can point your browser to the external IP address. If you use a https URL and your browser supports HTTP/2, then you will now be speaking HTTP/2 to Google Compute Engine!

Categories: Uncategorized