Web servers and networking · Intermediate · 17 min
HTTP/1.1, HTTP/2 and HTTP/3 compared, with curl
By Padding · Updated 18 Nov 2026
Ubuntu 26.04.1 LTS · Nginx 1.30.8 stable (nginx.org repo) · curl 8.18.0
You will serve one small site from Nginx over all three HTTP versions and use curl, openssl and h2load to see ALPN, multiplexing, header compression and HTTP/3 discovery for yourself.
On this page
Every browser and HTTP client still speaks HTTP/1.1, most sites also offer HTTP/2, and a growing share answer over HTTP/3. The three versions carry the same thing: a method, a path, headers, a status code and a body. What differs is how those bytes travel, and that decides how a page behaves on a slow or lossy network.
In this tutorial you will build a small lab site in Nginx that answers on port 8443 over all three versions, with a self-signed certificate. You will then use curl to request it as HTTP/1.1 and HTTP/2, watch one slow file hold up a small one on HTTP/1.1 but not on HTTP/2, count connections, measure header compression with h2load, and see how a client learns that HTTP/3 is on offer. The last step covers what QUIC changes and how to make an HTTP/3 request with a curl that supports it.
The lab uses port 8443 so it does not touch any site you already run on 443. Everything lives in ~/http-versions-demo, /etc/nginx/http-lab and one config file, and the last step removes them.
Step 1 · Check what your tools can speak
Install Nginx from nginx.org first, as in /tutorials/install-nginx-on-ubuntu-26-04. The nginx.org packages are built with both the HTTP/2 and HTTP/3 modules; Ubuntu's own package is an older release.
Install the client tools. curl and openssl are usually present already. nghttp2-client provides nghttp, which prints HTTP/2 frames, and h2load, a small load tester that reports header compression:
sudo apt-get install -y curl openssl nghttp2-client
command -v h2load nghttpAsk each tool which protocols it was built with:
nginx -V 2>&1 | grep -o -E 'with-http_v2_module|with-http_v3_module'
curl --version | head -n 1
curl --version | grep '^Features'Nginx prints both with-http_v2_module and with-http_v3_module. The first curl line names the version and libraries, for example curl 8.18.0 ... nghttp2/1.68.0. The Features line lists HTTP2 and alt-svc.
Look for HTTP3 in that Features line. Ubuntu 26.04's curl 8.18.0 is built without it: it links nghttp2 for HTTP/2 but not the ngtcp2 and nghttp3 libraries HTTP/3 needs. You can still do everything up to the last step with it, and the last step shows where to get a curl that has HTTP/3.
Check it worked
nginx -V shows with-http_v3_module, and you know whether your curl's Features line includes HTTP3. command -v h2load nghttp prints two paths.
Step 2 · Serve a lab site over all three versions
Browsers only use HTTP/2 over TLS, and HTTP/3 always includes TLS, so the lab needs a certificate. (curl can speak cleartext HTTP/2 with --http2-prior-knowledge, but browsers will not.) Create a private folder for it, then a self-signed certificate for localhost that lasts 30 days:
sudo install -d -m 700 /etc/nginx/http-lab
sudo openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes -days 30 \
-subj "/CN=localhost" -addext "subjectAltName=DNS:localhost,IP:127.0.0.1" \
-keyout /etc/nginx/http-lab/key.pem -out /etc/nginx/http-lab/cert.pemThe private key never leaves the root-only folder. Copy only the certificate into your demo folder, so curl can check the server against it instead of skipping the check with -k:
mkdir -p ~/http-versions-demo
sudo cat /etc/nginx/http-lab/cert.pem > ~/http-versions-demo/cert.pemCreate the site's files: twenty small text files that stand in for a page's icons and scripts, and one 200 KB file that will be sent slowly:
sudo install -d /usr/share/nginx/http-lab/assets
for i in $(seq -w 1 20); do
echo "asset $i" | sudo tee /usr/share/nginx/http-lab/assets/a$i.txt > /dev/null
done
sudo dd if=/dev/urandom of=/usr/share/nginx/http-lab/big.bin bs=1024 count=200 status=none
echo '<h1>HTTP versions lab</h1>' | sudo tee /usr/share/nginx/http-lab/index.html > /dev/nullNow the server block. One TCP listener serves HTTP/1.1 and HTTP/2 (TLS picks between them); a UDP listener with quic serves HTTP/3. http2 on; is the current way to switch HTTP/2 on; older guides put an http2 flag on the listen line, which Nginx now warns about. The Alt-Svc header tells clients that HTTP/3 is available on UDP port 8443:
sudo tee /etc/nginx/conf.d/http-lab.conf > /dev/null <<'NGINX'
server {
listen 8443 ssl;
listen 8443 quic reuseport;
http2 on;
http3 on;
server_name localhost;
ssl_certificate /etc/nginx/http-lab/cert.pem;
ssl_certificate_key /etc/nginx/http-lab/key.pem;
root /usr/share/nginx/http-lab;
add_header Alt-Svc 'h3=":8443"; ma=86400' always;
# Reports the protocol and connection the request arrived on.
location = /proto {
default_type text/plain;
return 200 "$server_protocol on connection $connection, request $connection_requests\n";
}
# Sent at 100 KB/s, so the 200 KB file takes about two seconds.
location = /big.bin {
limit_rate 100k;
}
}
NGINX
sudo nginx -tnginx -t ends with test is successful. Apply the change:
sudo systemctl reload nginxCheck it worked
Both listeners are open, one TCP and one UDP:
sudo ss -tlnp 'sport = :8443'
sudo ss -ulnp 'sport = :8443'Each command prints a line for port 8443 with nginx in the process column. The first is TCP (LISTEN), the second UDP (UNCONN, because UDP has no connections to listen for).
Step 3 · Watch HTTP/1.1 work one request at a time
Make an HTTP/1.1 request and print the conversation. -v shows lines curl sends with > and lines it receives with <:
curl --http1.1 -sv --cacert ~/http-versions-demo/cert.pem https://localhost:8443/proto 2>&1 \
| grep -E '^\* ALPN|^> GET|^< HTTP|^HTTP/'You see something like:
* ALPN: curl offers http/1.1
* ALPN: server accepted http/1.1
> GET /proto HTTP/1.1
< HTTP/1.1 200 OK
HTTP/1.1 on connection 3, request 1The request and status line are plain text, exactly as you could type them. The ALPN lines are the TLS handshake agreeing on the protocol before any HTTP is sent; more on that in the next step.
HTTP/1.1 keeps a connection open for further requests, but on each connection the next request cannot start until the previous response has fully arrived. Pipelining, sending requests back to back, is in the standard, but responses must still come back in the order the requests were sent (RFC 9112, section 9.3.2), and major browsers left it off or later removed it. First ask curl for the slow file and then the small one, reusing one connection:
curl --http1.1 -s --cacert ~/http-versions-demo/cert.pem \
-w '%{url_effective} connections opened: %{num_connects} took %{time_total}s\n' \
-o /dev/null https://localhost:8443/big.bin \
-o /dev/null https://localhost:8443/protoSomething like:
https://localhost:8443/big.bin connections opened: 1 took 2.01s
https://localhost:8443/proto connections opened: 0 took 0.0004sThe small request reused the connection (connections opened: 0) and was quick once it started, but it waited until big.bin had finished, two seconds in. Here curl queued the two requests itself; the protocol's part is that, on one HTTP/1.1 connection, a second response cannot overtake the first. So the only way to fetch both at once is a second connection. Ask curl to run the two transfers in parallel:
curl --http1.1 --parallel -s --cacert ~/http-versions-demo/cert.pem \
-w '%{url_effective} connections opened: %{num_connects} took %{time_total}s\n' \
-o /dev/null https://localhost:8443/big.bin \
-o /dev/null https://localhost:8443/protoSomething like:
https://localhost:8443/proto connections opened: 1 took 0.01s
https://localhost:8443/big.bin connections opened: 1 took 2.01sNow /proto finishes first, but each line says connections opened: 1: curl opened a second connection, with its own TCP and TLS handshake, to get it. That is the real cost of HTTP/1.1, one connection per request in flight, and it is why browsers open several connections to the same host.
Check it worked
The first command showed HTTP/1.1 200 OK and a body starting HTTP/1.1 on connection. In the one-after-the-other run, big.bin is printed first, with connections opened: 0 on the /proto line. In the --parallel run, /proto is printed first and both lines say connections opened: 1.
Step 4 · Switch to HTTP/2 and see multiplexing
Repeat the first request with --http2:
curl --http2 -sv --cacert ~/http-versions-demo/cert.pem https://localhost:8443/proto 2>&1 \
| grep -E '^\* ALPN|^< HTTP|^< alt-svc|^HTTP/'Something like:
* ALPN: curl offers h2,http/1.1
* ALPN: server accepted h2
< HTTP/2 200
< alt-svc: h3=":8443"; ma=86400
HTTP/2.0 on connection 4, request 1This is ALPN (Application-Layer Protocol Negotiation) at work. In the TLS handshake the client lists the protocols it speaks, and the server picks one. No extra round trip is spent on it. You can watch the same negotiation without curl:
openssl s_client -connect localhost:8443 -servername localhost -alpn h2,http/1.1 \
-CAfile ~/http-versions-demo/cert.pem < /dev/null 2>/dev/null | grep '^ALPN'It prints ALPN protocol: h2. Offer only -alpn http/1.1 and the server answers http/1.1 instead.
Under the text that curl prints, HTTP/2 sends binary frames. Each request and its response form a stream with its own number, and frames from different streams can share the connection in any order. nghttp shows the frames:
nghttp -nv https://localhost:8443/proto | grep -E 'recv (SETTINGS|HEADERS|DATA) frame'You see a SETTINGS frame on stream 0 (the connection itself), then a HEADERS frame and a DATA frame on the request's stream, an odd number. nghttp does not check certificates, which is fine against your own lab.
Now the slow and small files again, this time asked for at the same moment on one HTTP/2 connection. --parallel lets curl run transfers at once; curl prints each -w line when that transfer finishes:
curl --http2 --parallel -s --cacert ~/http-versions-demo/cert.pem \
-w '%{url_effective} connections opened: %{num_connects} took %{time_total}s\n' \
-o /dev/null https://localhost:8443/big.bin \
-o /dev/null https://localhost:8443/protoSomething like:
https://localhost:8443/proto connections opened: 0 took 0.01s
https://localhost:8443/big.bin connections opened: 1 took 2.02sThe small file finishes first while the big one is still arriving, and this time /proto says connections opened: 0: it shared the one HTTP/2 connection instead of needing a second.
Last, fetch all twenty small files in parallel over each version and count the connections curl opened:
args=()
for i in $(seq -w 1 20); do args+=(-o /dev/null "https://localhost:8443/assets/a$i.txt"); done
for version in --http1.1 --http2; do
printf '%s: ' "$version"
curl "$version" --parallel --parallel-max 20 -s --cacert ~/http-versions-demo/cert.pem \
-w '%{num_connects}\n' "${args[@]}" | awk '{n += $1} END {print n, "connections"}'
doneSomething like:
--http1.1: 20 connections
--http2: 1 connectionsThe HTTP/1.1 count may be a little under 20 if some transfers finished before others started, but it is always well above one. HTTP/2 carries all twenty on a single connection.
What this means for your front end
Several HTTP/1.1-era habits existed only to get around one request per connection:
- Domain sharding, spreading assets over
static1.example.com,static2.example.comand so on to get more connections. On HTTP/2 and HTTP/3 it costs extra DNS lookups and handshakes and splits traffic that could share one connection. Serve assets from as few hosts as you can. - Bundling everything into one file and image sprites. Many small requests are now cheap, and small files cache better: change one module and only that file is downloaded again. Bundlers still help with minifying and tree shaking, so keep them, but you no longer need one giant bundle.
- Inlining small images and CSS to save a request. It is rarely worth losing the cache for.
What does not change: bytes are bytes. Large images, heavy JavaScript and slow server responses cost the same on every version, and compression, caching headers and a CDN matter as much as before. On prepaid mobile data, common across much of Africa, the bytes you do not send matter more than the protocol you send them over.
Check it worked
The --http2 request showed ALPN: server accepted h2 and HTTP/2 200. In the parallel run /proto was printed before big.bin, and the twenty-file run reported 1 connections for --http2.
Step 5 · Measure header compression
Every HTTP request repeats headers the server has already seen: the host, the user agent, accept lists and often long cookies. HTTP/1.1 sends them as text every time. HTTP/2 compresses them with HPACK: both ends keep a table of headers sent earlier on the connection, and a repeated header is sent as a small index into that table instead of the full text.
h2load reports how much the headers it received shrank. Send 100 requests over one HTTP/2 connection:
h2load -n 100 -c 1 -m 10 https://localhost:8443/proto | grep -E '^(requests|traffic):'Something like:
requests: 100 total, 100 started, 100 done, 100 succeeded, 0 failed, 0 errored, 0 timeout
traffic: 12.74KB (13041) total, 7.23KB (7400) headers (space savings 41.27%), 3.70KB (3792) dataYour figures will differ a little. The space savings figure is how much smaller the response headers were on the wire than as text, here about 40 percent. Nginx gets that from HPACK's static table, which has fixed entries for common headers such as :status: 200, and from Huffman coding of the text. It does not add its response headers to the dynamic table, so a repeated server or alt-svc header is not shrunk to a one-byte index. Clients such as browsers and curl do use the dynamic table for the request headers they send, so repeated request headers, including long cookies, shrink to a few bytes after the first request; h2load only reports the headers it receives. Like nghttp, h2load does not check certificates.
Run the same load over HTTP/1.1 for comparison:
h2load --h1 -n 100 -c 1 https://localhost:8443/proto | grep '^traffic:'The headers figure is almost twice as large for the same 100 responses, and the savings are 0.00%: HTTP/1.1 sends every header as plain text.
HTTP/3 uses QPACK, a close relative of HPACK. HPACK relies on frames arriving in order, which TCP guarantees. QUIC streams can arrive out of order, so QPACK sends table updates on separate streams and lets each request say which table entries it depends on. That way, a lost packet carrying a table update does not have to stall every request.
Check it worked
The HTTP/2 traffic: line shows space savings of roughly 40 percent, and the --h1 run shows a larger headers byte count and space savings 0.00% for the same 100 requests.
Step 6 · See how a client finds HTTP/3
HTTP/2 fixed head-of-line blocking at the HTTP layer, but it still runs on TCP. TCP delivers one ordered stream of bytes, so if one packet is lost, everything after it waits for the resend, including frames of streams that lost nothing. On a clean connection you never notice. On a mobile network that drops a few percent of packets, one HTTP/2 connection can do worse than six HTTP/1.1 connections.
HTTP/3 moves to QUIC, a transport that runs over UDP. QUIC knows about streams itself, so a lost packet only delays the stream whose data it carried. It also builds TLS 1.3 into its handshake, so a new connection is ready after one round trip instead of the TCP handshake plus the TLS handshake, and it identifies connections by an ID rather than by IP address and port. That last part allows connection migration: a phone that moves from Wi-Fi to mobile data keeps its connection, where TCP would have to start again. Both help most on the networks many readers use every day: busy mobile networks, low-end Android phones switching between Wi-Fi and data, and links with high latency.
A client cannot know in advance that a server speaks QUIC on UDP. The usual way it learns is the Alt-Svc header on an HTTP/1.1 or HTTP/2 response:
curl --http2 -sI --cacert ~/http-versions-demo/cert.pem https://localhost:8443/ | grep -i '^alt-svc'It prints alt-svc: h3=":8443"; ma=86400: HTTP/3 is on UDP port 8443 of the same host, and the client can remember that for 86,400 seconds (one day). A browser makes its first request over TCP, sees the header, and tries QUIC on later connections, falling back to TCP if UDP is blocked. Sites can also advertise HTTP/3 in a DNS HTTPS record, so the very first connection can use it.
If your curl lists HTTP3 in its features, make an HTTP/3-only request. On macOS or Linux, Homebrew's curl is built with HTTP/3 (brew install curl, then use the full path it prints, because the system curl comes first on your PATH):
curl --http3-only -sv --cacert ~/http-versions-demo/cert.pem https://localhost:8443/proto 2>&1 \
| grep -E '^\* (ALPN|QUIC|Connected)|^< HTTP|^HTTP/'The output includes something like < HTTP/3 200 and the body HTTP/3.0 on connection 9, request 1. --http3-only fails rather than falling back, which is what you want for a test; --http3 tries QUIC and quietly falls back to TCP. Ubuntu 26.04's curl refuses both options with an error saying the installed libcurl does not support them.
To test from another computer, open UDP 8443 as well as TCP 8443 in UFW and in your cloud provider's firewall (sudo ufw allow 8443/udp), and copy cert.pem to that machine for --cacert. A public site uses UDP 443 and a trusted certificate; /tutorials/turn-on-http-2-and-http-3-in-nginx covers that setup. In a browser's developer tools, the Network panel's Protocol column shows h2 or h3 for each request.
Check it worked
The alt-svc line shows h3=":8443". If you have an HTTP/3 curl, its response shows HTTP/3 200 and a body that starts HTTP/3.0.
Step 7 · Clean up
Remove the lab's config first, then test and reload Nginx, then delete its files. Check the paths before you run the rm commands: they delete these folders and everything in them.
sudo rm /etc/nginx/conf.d/http-lab.conf
sudo nginx -tsudo systemctl reload nginxsudo rm -r /etc/nginx/http-lab /usr/share/nginx/http-lab
rm -r ~/http-versions-demoIf you opened port 8443 in UFW, close it again with sudo ufw delete allow 8443/udp and, if you added it, sudo ufw delete allow 8443/tcp. To remove the client tools, run sudo apt-get remove nghttp2-client.
Check it worked
sudo ss -tulnp 'sport = :8443' | grep -c nginx || trueThe command prints 0: nothing listens on port 8443 any more.
Next steps
- Turn on HTTP/2 and HTTP/3 for a real site on port 443:
/tutorials/turn-on-http-2-and-http-3-in-nginx. - See the DNS, TCP and TLS phases that come before any HTTP version:
/tutorials/how-a-request-reaches-your-server. - Watch the TCP handshake and the packets behind these requests:
/tutorials/watch-a-tcp-connection-with-tcpdump. - Use curl's timers to find where a slow page spends its time:
/tutorials/debug-a-slow-or-failing-website-with-curl.
Related tutorials
- Write Nginx location blocks that match what you expectYou will build a practice Nginx 1.30 server where every location block labels its responses, predict which block answers each of twelve URLs, check your answers with curl, and fix the alias, regex-order and proxy_pass mistakes that catch most people out.
- Write a server firewall with nftablesYou will write one /etc/nftables.conf with a default-drop input chain, rate-limited SSH, named address sets, counters and logging, and load it over SSH behind a timer that undoes it if you lose your connection.
- Watch a TCP connection open and close with tcpdumpYou will capture a curl request to a local web server with tcpdump on Ubuntu 26.04, read its handshake, data and teardown line by line, see the reset a closed port sends, and save, filter and rotate captures as pcap files.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials