Skip to content

Instantly share code, notes, and snippets.

@andrewchilds
Last active July 10, 2025 21:23
Show Gist options
  • Select an option

  • Save andrewchilds/2393d6017c0b4a6e79d635243804fd12 to your computer and use it in GitHub Desktop.

Select an option

Save andrewchilds/2393d6017c0b4a6e79d635243804fd12 to your computer and use it in GitHub Desktop.

Revisions

  1. andrewchilds revised this gist Jun 27, 2023. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,6 @@

    This was tested to work using HAProxy 2.8 on Ubuntu 20.04.

    I'm not sure if `mode http` is a necessary line or not.

    ### Use case

    This lets you run a cluster of API servers configured to use HTTP/2 (for example, Fastify using `{ http2: true }`), behind a HAProxy LB, so that you can serve typical REST API requests as well as SSE (Server Side Events) streaming connections, so that you can do fancy real-time page updates in your app.
  2. andrewchilds revised this gist Jun 27, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,6 @@ I'm not sure if `mode http` is a necessary line or not.

    ### Use case

    This lets you run a cluster of API servers running Fastify, configured to use HTTP/2 (`{ http2: true }`), behind a HAProxy LB, so that you can serve typical REST API requests as well as SSE (Server Side Events) streaming connections, so that you can do fancy real-time page updates in your app.
    This lets you run a cluster of API servers configured to use HTTP/2 (for example, Fastify using `{ http2: true }`), behind a HAProxy LB, so that you can serve typical REST API requests as well as SSE (Server Side Events) streaming connections, so that you can do fancy real-time page updates in your app.

    Using HTTP/2 resolves the "6 concurrent HTTP connections" limit imposed by Chrome/Firefox/etc, which means the web app would become unresponsive if the user has 6+ tabs open with the app simultaneously.
  3. andrewchilds revised this gist Jun 22, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,6 @@ I'm not sure if `mode http` is a necessary line or not.

    ### Use case

    This allows me to run a cluster of API servers running Fastify, configured to use HTTP/2 (`{ http2: true }`), behind a HAProxy LB, to allow me to serve typical REST API requests as well as SSE (Server Side Events) stream connections.
    This lets you run a cluster of API servers running Fastify, configured to use HTTP/2 (`{ http2: true }`), behind a HAProxy LB, so that you can serve typical REST API requests as well as SSE (Server Side Events) streaming connections, so that you can do fancy real-time page updates in your app.

    Using HTTP/2 resolves the "6 concurrent HTTP connections" limit imposed by Chrome/Firefox/etc, which means the web app would become unresponsive if the user has 6+ tabs open with the app simultaneously.
  4. andrewchilds created this gist Jun 22, 2023.
    11 changes: 11 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    ## How to configure HAProxy to support end-to-end (e2e) connections that switch from h2 to h2c

    This was tested to work using HAProxy 2.8 on Ubuntu 20.04.

    I'm not sure if `mode http` is a necessary line or not.

    ### Use case

    This allows me to run a cluster of API servers running Fastify, configured to use HTTP/2 (`{ http2: true }`), behind a HAProxy LB, to allow me to serve typical REST API requests as well as SSE (Server Side Events) stream connections.

    Using HTTP/2 resolves the "6 concurrent HTTP connections" limit imposed by Chrome/Firefox/etc, which means the web app would become unresponsive if the user has 6+ tabs open with the app simultaneously.
    12 changes: 12 additions & 0 deletions haproxy.cfg
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    frontend http_front
    mode http
    bind *:80
    bind *:443 ssl crt /etc/haproxy/ssl/YOURDOMAIN.pem alpn h2,http/1.1
    redirect scheme https if !{ ssl_fc }
    default_backend http_back

    backend http_back
    mode http
    balance roundrobin
    server api1 1.2.3.4:4000 proto h2 check
    server api2 1.2.3.5:4000 proto h2 check