Birb
Birb

Reputation: 53

How does Varnish handle HTTP/2 Server Push?

I have been looking at ways to improve page loads using HTTP2 specifically using server push.

We have a HAProxy => Varnish => Apache configuration.

I know varnish 5 can handle HTTP2 requests, but when the request has server push headers for further resources on a page do those resources come out of the cache or does it just get passed to apache?

My thinking is that if those server push headers don't get handled by varnish it would be to the determent of page loads rather than a net gain...

Upvotes: 4

Views: 2689

Answers (2)

Barry Pollard
Barry Pollard

Reputation: 45970

HAProxy 1.8 only has HTTP/2 support at the front end and then will connect to Varnish using HTTP/1.1 - unless you are using this as a TCP loadbalancer rather than a HTTP loadbalancer? HAproxy 1.9 did add HTTP/2 in the backend (i.e. to downstream systems like Varnish in your setup). I do not believe either supports HTTP/2 Push when using it as a HTTP proxy.

Varnish similarly only supports HTTP/2 over the front end and not push AFAIK.

So basically you cannot use Push in your currently infrastructure. They will connect to Apache (which is the only piece with Push support) as a HTTP/1.1 connection and therefore it will not even attempt to Push resources unless using HTTP/2.

The easiest way to support this would be to simplify your infrastructure. I’m not sure if you have the volume that requires both HAProxy and Varnish or if you have some other reason to set this up this way? If not then you could either get rid of them totally and just use Apache. Alternatively just use HAProxy as a TCP proxy and connect to any Apache instances (either over TLS or not) using HTTP/2.

The other option is to put another instance of Apache in front of HAProxy to handle HTTP/2 and HTTP/2 Push. The back end connections can be over HTTP/1 then and signal to this new Apache to push a resource using Link headers (even over HTTP/1) and it will request the resource from downstream appropriately (which may read it from the Varnish cache if it’s set up that way). But running Apache -> HAProxy -> Varnish -> Apache definitely sounds like overkill for most sites.

Upvotes: 4

Michael Leeming
Michael Leeming

Reputation: 51

HTTP/2 Push is now supported in HAproxy 1.9 with "option http-use-htx" It can use Varnish (and other non-TLS) as HTTP/2 backend servers with parameter "proto h2".

It can also use TLS HTTP/2 enabled backend servers with parameter "ssl verify none alpn h2"

However I'm strucling with Varnish 6.0 to allow HTTP/2 Push back to another HAproxy Frontend with "proto h2" enabled, as Varnish seems to only support HTTP/1.1 to its backend servers. Even though varnishlog shows HTTP/2 protocol is used in the request from HAProxy.

I have tested the following and it works all the way with HTTP/2 (end-2-end).

HTTP/2-browser -> Public-HAProxy-h2frontend -> Back-HAProxy-h2frontend-> HTTP/2-SSL-Webserver (IIS)

The following fails after Varnish, as it only uses http/1.1 to the Back-HAProxy-h2frontend, need to be able to force varnish to keep using HTTP/2 to the backend server.

HTTP/2-browser -> Public-HAProxy-h2frontend -> HTTP/2-Varnish -> Back-HAProxy-h2frontend-> HTTP/2-SSL-Webserver (IIS)

Upvotes: 1

Related Questions