basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    HTTP and TLS: handshake, SNI, certificate verification, and HTTP/1.1–3

    After the TCP handshake, client and server establish an encrypted TLS 1.3 channel: the client sends the hostname in SNI, verifies the certificate chain, and only then sends the HTTP request. Covers curl -vI output, serving dozens of sites on one IP via SNI, and how HTTP/1.1, HTTP/2, and HTTP/3 differ.

    What you’ll get

    Run curl -vI https://example.org to inspect all three top layers in one output: TCP connect, the TLS 1.3 handshake with HTTP/2 selected via ALPN, and the HTTP response headers:

    curl -vI https://example.org
    # *   Trying 203.0.113.10:443...
    # * Connected to example.org (203.0.113.10) port 443
    # * ALPN: curl offers h2,http/1.1
    # * SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 / X25519 / id-ecPublicKey
    # * ALPN: server accepted h2
    # * Server certificate:
    # *  subject: CN=example.org
    # *  start date: Sep 26 22:05:05 2026 GMT
    # *  expire date: Dec 25 22:13:27 2026 GMT
    # *  subjectAltName: host "example.org" matched cert's "example.org"
    # *  issuer: C=US; O=SSL Corporation; CN=Cloudflare TLS Issuing ECC CA 3
    # *  SSL certificate verify ok.
    # * using HTTP/2
    # > HEAD / HTTP/2
    # > Host: example.org
    # < HTTP/2 200
    # < content-type: text/html; charset=utf-8
    # < cache-control: max-age=14400
    # < alt-svc: h3=":443"; ma=86400

    That single SSL connection using… line describes every parameter of the encrypted channel:

    curl -vI https://example.org · Pick a segment
    Next, curl prints the certificate fields (subjectAltName, issuer, dates) and sends HEAD / HTTP/2 only after SSL certificate verify ok.

    What happens between TCP and the first byte of HTML

    Once the TCP handshake opens port 443 (TCP: flags and states), the channel is still plaintext. TLS 1.3 runs first:

    TCP established (:443)

    1. ClientHelloSNI · ALPN · keyThe client sends the target hostname in the SNI extension, its supported ALPN protocols (h2, http/1.1), and its X25519 key share.
    2. ServerHello + Cert1 RTT in TLS 1.3The server picks the matching certificate by SNI, replies with its key share, turns on encryption immediately, and sends the certificate chain and signature already encrypted.
    3. Certificate checkSAN · dates · CAThe client checks three conditions: the hostname matches subjectAltName, current time falls between start and expire, and the signature chain leads to a root CA in the local trust store.
    4. HTTP exchangeHEAD / · 200 OKThe channel is verified and encrypted. The HTTP request (GET/POST, headers, Host: example.org) goes out and the status code and body return.

    HTTP/2 200 OK (inside TLS)

    Why SNI exists (Server Name Indication, RFC 6066). One server on a single IP 203.0.113.10 often hosts dozens of sites behind Traefik or nginx (Traefik). The HTTP Host: example.org header travels only after TLS is up, yet the server must pick a certificate before that. The client solves this by sending the domain name up front inside the SNI extension of the first ClientHello packet.

    Check which certificate a server returns for a given SNI (and whether fullchain is in place) with openssl s_client — the -servername flag sets SNI:

    openssl s_client -connect 203.0.113.10:443 -servername example.org </dev/null 2>/dev/null \
      | openssl x509 -noout -subject -issuer -dates
    # subject=CN = example.org
    # issuer=C = US, O = SSL Corporation, CN = Cloudflare TLS Issuing ECC CA 3
    # notBefore=Sep 26 22:05:05 2026 GMT
    # notAfter=Dec 25 22:13:27 2026 GMT

    Three TLS verification patterns

    1. ClientHello✓ SNI: example.org
    2. Server :443✓ fullchain + ALPN h2
    3. CA check✓ SAN and dates valid
    4. HTTP/2✓ 200 OK
    * SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 / X25519
    * subjectAltName: host "example.org" matched cert's "example.org"
    * SSL certificate verify ok.
    < HTTP/2 200
    What happened

    The server selected the certificate by SNI, sent the full chain to a trusted CA, and negotiated HTTP/2.

    Check with

    curl -vI https://example.org

    1. ClientHello✓ SNI: shop.example.org
    2. Proxy :443✕ served default cert
    3. SAN check✕ hostname mismatch
    4. curl (exit 60)✕ aborted before HTTP
    * Server certificate: subject: CN=TRAEFIK DEFAULT CERT
    curl: (60) SSL: no alternative certificate subject name matches target host name 'shop.example.org'
    Cause

    The reverse proxy had no certificate for shop.example.org (or no router for that hostname) and fell back to its self-signed default cert.

    Check with

    openssl s_client -connect 203.0.113.10:443 -servername shop.example.org </dev/null

    1. Server :443✕ served cert.pem only
    2. Browser✓ fetched chain itself
    3. curl / Python✕ chain stopped short of root
    curl: (60) SSL certificate problem: unable to get local issuer certificate
    # openssl s_client -showcerts prints only one certificate (depth=0) instead of a chain
    Cause

    The web server config points to the leaf certificate instead of fullchain.pem: browsers hid the gap via AIA caching while scripts and APIs failed.

    Check with

    openssl s_client -showcerts -connect example.org:443 -servername example.org </dev/null

    HTTP status codes and versions HTTP/1.1, HTTP/2, and HTTP/3

    HTTP runs inside that encrypted channel: a request consists of a method (GET, HEAD, POST), a path, headers (Host, Authorization, Content-Type), and an optional body; the reply starts with a three-digit status code:

    • 2xx — success (200 OK, 204 No Content).
    • 3xx — redirect (301/308 permanent, 302/307 temporary with the target in Location, 304 Not Modified to reuse cache).
    • 4xx — client or routing error (400 malformed request, 401 unauthenticated, 403 forbidden, 404 route not found, 429 rate limit hit).
    • 5xx — server failure (500 application error, 502 backend unreachable from proxy, 503 service overloaded, 504 backend timeout).

    Methods and status codes mean the same thing across every HTTP version — what changes is how data is framed on the transport layer:

    Version Transport Framing Multiplexing per connection Key difference
    HTTP/1.1 TCP Plain text Sequential (browsers open up to 6 TCP connections per host) Still the standard between a reverse proxy and a local backend
    HTTP/2 TCP + TLS (ALPN h2) Binary frames Dozens of streams in one TCP connection, HPACK header compression Losing one TCP packet stalls every stream on the connection
    HTTP/3 UDP + QUIC (UDP and QUIC) Binary frames Independent QUIC streams, QPACK compression No cross-stream head-of-line blocking; survives Wi-Fi / LTE switches
    One server `203.0.113.10:443` runs both `app.example.org` and `docs.example.org` behind Traefik with different certificates. How does the server know which certificate to send?
    curl -vI --resolve docs.example.org:443:203.0.113.10 https://docs.example.org
    One server `203.0.113.10:443` runs both `app.example.org` and `docs.example.org` behind Traefik with different certificates. How does the server know which certificate to send?
    Answer:
    ClientHello (SNI: docs.example.org) -> server picks the docs.example.org certificate

    The HTTP Host: header is sent inside the encrypted channel, so the server cannot read it while choosing a certificate. The target hostname arrives in the SNI extension during the TLS handshake.

    A site opens in browsers with no warning, while mobile apps and `curl` fail with `unable to get local issuer certificate`. What should you check first?
    openssl s_client -showcerts -connect example.org:443 -servername example.org </dev/null 2>/dev/null | grep -E 's:|i:'
    A site opens in browsers with no warning, while mobile apps and `curl` fail with `unable to get local issuer certificate`. What should you check first?
    Answer:
    openssl s_client -showcerts: shows one certificate instead of a chain (depth 0 + 1)

    When the intermediate CA certificate is missing, browsers often fill the gap from cache or via the certificate's AIA URL, whereas curl, OpenSSL, and language standard libraries reject the connection.

    If it doesn’t work

    curl https://example.org fails with SSL: no alternative certificate subject name matches target host name

    Cause
    The server presented a certificate for another domain (or its default fallback cert): the requested domain is missing from the certificate's SAN field, or the reverse proxy has no route matching that SNI.
    Fix
    Inspect the exact certificate returned by the server: openssl s_client -connect 203.0.113.10:443 -servername example.org </dev/null 2>/dev/null | openssl x509 -noout -subject -ext subjectAltName.

    A site loads cleanly in browsers, while curl, Python, or Go fail with unable to get local issuer certificate

    Cause
    The web server sends only the leaf certificate (cert.pem) without the intermediate (chain.pem). Browsers fetch missing intermediates on their own, while CLI tools and libraries require the full chain.
    Fix
    Point nginx or Traefik to the full chain file (fullchain.pem) and check the output of openssl s_client -showcerts -connect example.org:443 -servername example.org </dev/null.

    The certificate validates on another machine, yet curl on this server reports certificate is not yet valid or certificate has expired

    Cause
    Either the certificate expired (broken ACME/Let's Encrypt renewal) or the local system clock has drifted.
    Fix
    Check the system clock (timedatectl) and the certificate validity dates (openssl x509 -noout -dates). If expired, check renewal logs in Traefik or certbot.

    https://example.org loads fine, while https://203.0.113.10 returns 404 and a certificate warning

    Cause
    Multiple sites share one IP behind a reverse proxy: routing and certificate selection depend on the domain name in SNI and the Host header, which do not match any rule when you connect by raw IP.
    Fix
    To test a specific IP without touching DNS, pass the hostname explicitly: curl -vI --resolve example.org:443:203.0.113.10 https://example.org.

    The TLS handshake succeeds, but the server responds with HTTP/2 502 or 504

    Cause
    The client connected to the reverse proxy (nginx, Traefik, Cloudflare), while the backend behind it is down (502 Bad Gateway) or missed its timeout (504 Gateway Timeout).
    Fix
    Debug behind the proxy: check the backend container or service (docker ps, ss -tulnp) and the proxy logs (Traefik).