nghttp2.org

HTTP/2 C library and tools

Nghttpx: Reverse Proxied to H2

nghttp2.org has been powered by nghttpx reverse proxy. It forwards most of the requests to backend nginx. And resources under /httpbin is forwarded to httpbin server. Previously, all backend forward link is cleartext HTTP/1.1. Now, with the new feature added to nghttpx, we forwards requests to nginx in HTTP/2 protocol.

nghttpx in the current nghttp2 master branch has a feature to specify backend protocol per host/request path routing pattern. So we just specify the following 2 options to make the above routing work:

1
2
backend=127.0.0.1,8080;;proto=h2
backend=unix:/var/unix/httpbinsv.sock;/httpbin/;proto=http/1.1

The above configuration means that all requests whose path starts with /httpbin/ are forwarded to UNIX domain socket unix:/var/unix/httpbinsv.sock via HTTP/1.1 protocol. The rest of the requets are forwarded to server listening 127.0.0.1:8080 via HTTP/2 protocol.

The microbench mark shows that using HTTP/2 backend connection reduces backend TCP connection to about 1/100 (because of the concurrency in HTTP/2 protocol, and we coalesce frontend connections into fewer backend HTTP/2 connections), and roughly 2 times faster than HTTP/1.1 backend. HTTP/2 backend is a bit slower with default 64KiB stream window when transferring large objects, but it could be remedied by using larger window.