Nginx HTTP/2 and ALPN
Two requests, one connection
A browser downloading a stylesheet and a picture does not need to wait for each response to finish before sending the next request. HTTP/2 separates traffic into numbered streams within a single connection. Frames from different streams can be interleaved. The browser uses those numbers to associate frames with the correct response. HTTP/2 still uses TCP, so a missing TCP segment can delay several streams at once. Multiplexing removes a specific HTTP/1.1 ordering bottleneck, not every possible delay.
stream 1: HEADERS /style.cssstream 3: HEADERS /photo.pngstream 3: DATA ...stream 1: DATA ...The image can make progress before the stylesheet finishes. The numbers are illustrative client-initiated stream IDs; frames are not raw HTTP/1.1 text.
Enable HTTP/2 for a TLS virtual host
ALPN (Application-Layer Protocol Negotiation) is part of the TLS handshake. A client advertises supported application protocols, and the server selects one in common. Nginx needs its HTTP/2 module and an ALPN-capable TLS library. The local binary advertises --with-http_v2_module, but the lab requires a supported patched build. In Nginx 1.25.1 and later, use the separate http2 directive. Older releases used the http2 parameter of listen; do not copy it into new deployments without checking compatibility. The following server fragment assumes an existing http context and lab certificate files.
server { listen 127.0.0.1:9443 ssl; server_name localhost; http2 on; ssl_certificate certs/server.crt; ssl_certificate_key certs/server.key; location = /health { return 200 "ready\n"; }}The listener accepts TLS traffic and can negotiate h2; a compatible HTTP/1.1 client can still use the same TLS endpoint. Cleartext HTTP/2 is a separate prior-knowledge lab option, not an encrypted transport.
Verify the negotiated protocol
A successful HTTPS request alone does not establish HTTP/2. Check both certificate verification and the selected protocol. These commands are optional live tests in the prepared local lab, not executed results. curl must include HTTP/2 support (check curl -V). openssl requires a suitable local trust file and hostname.
openssl s_client -connect 127.0.0.1:9443 -servername localhost -alpn h2 -CAfile certs/server.crt -verify_hostname localhost -verify_return_error </dev/nullcurl --noproxy "*" --http2 --max-time 5 --cacert certs/server.crt --resolve localhost:9443:127.0.0.1 -sS -o /dev/null -w "%{http_version}\n" https://localhost:9443/healthExpected ALPN is h2 and curl reports 2. A negotiated http/1.1 is still HTTPS but fails the HTTP/2 objective. No verification bypass is necessary.
The two HTTP connections are independent
The browser-to-Nginx protocol does not determine the Nginx-to-backend protocol. Ordinary HTTP proxying on 1.26.3 can explicitly use HTTP/1.1. The current proxy module documentation adds upstream HTTP/2 as proxy_http_version 2 from 1.29.4, with the HTTP/2 module required. The default changed from 1.0 to 1.1 in 1.29.7. Neither change establishes that a particular backend implements gRPC. Keep the dedicated gRPC route in the next lesson.
location /web/ { proxy_http_version 1.1; proxy_pass http://127.0.0.1:9080;}A browser may negotiate h2 while this upstream receives HTTP/1.1. This illustrative fragment needs an HTTP backend on 9080, not the gRPC backend in the lab.
Read resource limits correctly
HPACK compresses HTTP/2 header fields; it is not compression of the message body. Flow control limits DATA in flight on streams and connections, giving the receiver a way to manage backpressure. A stream-count limit is per connection, not a global concurrency cap. Use measured workloads to size it; do not infer capacity from one successful request.
Practice and next step
Predict the negotiated protocol separately on each hop, then use a client to verify it. Next: configure a native gRPC proxy. Use the chapter 22 manual exercise and optional lab. All configuration samples are static; no ByteMind execution is implied.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Nginx HTTP/2 and ALPN
Enable HTTP/2 on a TLS listener, interpret protocol negotiation, and distinguish the client and upstream connections.
What does ALPN h2 establish?
A browser requests CSS and an image at once. What enables independent HTTP/2 progress?
What is the modern configuration on Nginx 1.26.3?
A client uses h2 while proxy_http_version is 1.1. What does the ordinary HTTP backend receive?
A stream limit of 16 is configured. What does it limit?