Skip to content
HTTPS & Kernel Tuning: TLS Handshakes, Session Reuse, and Nginx/Linux Optimization
Operations 49 min read

HTTPS & Kernel Tuning: TLS Handshakes, Session Reuse, and Nginx/Linux Optimization

This article analyzes three real HTTPS incidents—incomplete certificate chains, disabled session reuse halving QPS, and misapplied kernel parameters causing packet loss—then provides complete production configurations for Nginx TLS 1.2/1.3, session caching, OCSP stapling, HSTS, and Linux kernel parameters with explanations of their physical boundaries and troubleshooting commands.

Architecture Pony
Architecture Pony
Architecture Pony

Introduction

HTTPS in Nginx is a classic case of "copy a template and it runs, but everywhere are pits": missing one certificate in the chain breaks Android and Java clients; disabling session reuse halves QPS without obvious cause; blindly copying kernel "optimization lists" turns TIME_WAIT and conntrack into new failure sources. This article separates the encryption layer from the OS layer: what each TLS handshake round does, certificate chain and SNI trust logic, boundaries of four kernel parameter groups, and finally two complete production-ready configurations.

Three Incidents, Three Lessons

Incident 1: PC Works, All Apps Fail Handshake

After certificate renewal, browsers worked but iOS and Java clients threw SSLHandshakeException. Root cause: only the leaf certificate (domain.crt) was configured, intermediate certificates were not concatenated . Browsers use AIA (Authority Information Access) to auto-fetch missing intermediates and cache them; most mobile and Java clients do not, so chain validation fails. The server must send leaf + intermediate; the root always resides in the client's trust store. This is the most common "looks fine" HTTPS launch issue.

Incident 2: Switching to HTTPS Halves QPS

Same machine, same API: HTTP benchmarked at 120k QPS, HTTPS dropped to 50k with CPU saturated on Nginx workers. Configuration check revealed ssl_session_cache was not set (default none), so every request performed a full handshake: RSA private-key operation, key exchange, certificate transmission all repeated . Enabling shared session cache + session tickets raised reuse rate to 92% and QPS recovered to 110k. TLS overhead is almost entirely in the handshake, and handshakes can be amortized via session reuse—this saves more CPU than switching any cipher suite.

Incident 3: Copying sysctl "Optimization" Causes Random Packet Loss

Ops applied an internet "million-concurrency optimization" list: net.ipv4.tcp_tw_recycle=1, net.ipv4.tcp_max_tw_buckets=2000. Hours later random request timeouts appeared, users behind NAT couldn't connect, dmesg showed nf_conntrack: table full, dropping packet. tw_recycle drops connections with out-of-order timestamps under NAT (removed in newer kernels), too-small max_tw_buckets forces connection recycling, and a full conntrack table silently drops packets —every kernel tuning knob has preconditions; copying a checklist imports someone else's environment assumptions into your own incidents.

Technical Analysis: Handshakes, Certificates, and Kernel

1.1 What TLS Handshake Actually Does

TLS 1.2 full handshake takes two RTTs:

First RTT — ClientHello (versions, suites, random, SNI), ServerHello (chosen suite, random) + Certificate (chain) + ServerKeyExchange (ECDHE params) + ServerHelloDone.

Second RTT — Client validates chain, generates pre-master secret encrypted (ClientKeyExchange), switches cipher and Finished; server Finishes; then encrypted application data flows.

TLS 1.3 moves key exchange into the first flight , needing only 1-RTT; session reuse can achieve 0-RTT sending data immediately (but with replay risk, suitable only for idempotent requests). Understanding this timeline matters because: RTT is set by physical distance, handshake rounds by protocol version, and crypto compute by suite and key type —three variables mapping to protocol upgrade, session reuse, and algorithm selection.

Two key-exchange types:

RSA key exchange (legacy) — Client encrypts pre-master with server's public key; if private key leaks, historical traffic is decryptable.

ECDHE (modern default) — Both sides contribute ephemeral parameters to derive session keys, providing Forward Secrecy: private key leak does not compromise past traffic .

Modern config principle: only TLS 1.2 ECDHE suites + TLS 1.3, disable RSA key exchange and all CBC modes (padding oracle risk).

1.2 Certificate Chain and SNI: Two Trust Logics

Certificate chain is three layers: Root CA (pre-installed in OS/browser trust store) → Intermediate (signed by root) → Leaf (your domain, signed by intermediate) . Server must send "leaf + intermediate"; client validates using local root. When intermediate is missing, browsers use AIA extension to auto-fetch; other clients do not —this explains Incident 1's "PC OK, Apps all fail". One command verifies: openssl s_client -connect a.com:443 -showcerts to see how many certs server returns, or openssl verify -CAfile full_chain.

SNI solves "multiple HTTPS sites on one IP": HTTP uses Host header for virtual hosting, but HTTPS handshake occurs before request encryption and before Host header exists, so it relies on ClientHello's SNI field (plaintext domain name) . Two config points: ① each server block must have correct server_name; Nginx matches cert by SNI. ② Must have a default_server fallback —old clients without SNI (some old Java, legacy crawlers) send no domain, fall to default server and get wrong cert, manifesting as "certificate domain mismatch". SAN certs and wildcards reduce cert count, but wildcard covers only one subdomain level ( *.a.com excludes x.y.a.com).

1.3 Performance Accounting: Handshake Is the Cost Bulk

TLS cost splits into asymmetric ops (handshake) and symmetric encryption (transfer) . Latter has AES-NI hardware acceleration, nearly negligible (several GB/s on modern CPUs); former is all CPU-intensive modular exponentiation and elliptic-curve point multiplication—RSA-2048 one signature ~1ms CPU time, ECDSA P-256 ~⅓ of that, and a full handshake performs multiple such ops. Therefore HTTPS optimization core is not "switch to faster cipher" but "do fewer handshakes" : session reuse eliminates asymmetric ops on subsequent handshakes—this is the real reason Incident 2's QPS doubled. Key type choice matters: ECDSA certs (P-256) sign faster, are smaller, save handshake bytes; trade-off is older client compatibility. Dual certs (RSA + ECDSA) let server negotiate best match per client—standard practice for large sites.

1.4 Session Reuse Trio

Two independent paths: session cache (server stores state, client presents Session ID) and session ticket (server encrypts state, client stores it, returns for auto-decrypt) . Nginx controls them via: ssl_session_cache shared:SSL:10m enables shared cache (10m ≈ 40k sessions, shared across workers); ssl_session_timeout sets lifetime (default 5 min, can extend to 1 hour); ssl_session_tickets on enables tickets. Production notes: Enable both —cache stable for same client, ticket falls back on cache miss; Multi-node must sync ticket key ( ssl_session_ticket_key pointing to same key file, rotated periodically), otherwise load balancer routing to another node fails ticket decryption, reuse fails, showing "reuse rate fluctuates".

1.5 HTTP/2 and Security Headers

HTTP/2 negotiated via ALPN during handshake, multiplexes all requests over one TCP connection , almost free win for HTTPS sites (saves repeated connection handshakes). Two caveats: ① Server push deprecated by major browsers, don't configure; ② HTTP/2 flow control and single-connection nature means rate limiting must shift from "connection count" to "request/stream count" — limit_conn weakly constrains h2's multi-request single connection, which is why limit_req (covered in article 05) is more important. Security headers only meaningful under HTTPS: HSTS forces browser to use HTTPS thereafter (max-age start at 6 months, preload irreversible), X-Content-Type-Options nosniff, X-Frame-Options or CSP against clickjacking.

1.6 Kernel Parameters: Four Groups, Each with Physical Boundaries

Kernel tuning often copied as "universal checklist"; actually only four groups truly affect Nginx, each with boundaries:

Connection queues — net.core.somaxconn is completed-handshake accept queue ceiling; listen backlog also bounded by it (min of both). net.ipv4.tcp_max_syn_backlog is half-open queue.

Ports and TIME_WAIT — net.ipv4.ip_local_port_range determines local ports for outbound connections (critical for reverse proxy). tcp_max_tw_buckets too small forces recycling causing connection anomalies. tcp_tw_recycle removed in new kernels and harmful under NAT, never enable .

File descriptors — fs.file-max, fs.nr_open, systemd LimitNOFILE three layers all must suffice; missing one yields "too many open files" (Incident 01 replay).

Memory and conntrack — net.netfilter.nf_conntrack_max and hashsize set NAT/iptables tracking table capacity; table full = silent packet drop , root cause of Incident 3. net.ipv4.tcp_mem and socket buffers affect memory under high concurrency.

Core Workflows and Complete Production Configs

2.1 Complete Config 1: HTTPS Production Site

Covers all three incidents' root causes: full cert chain, SNI + default_server, TLS 1.2/1.3 + ECDHE suites, dual-path session reuse, OCSP stapling, HSTS + security headers, HTTP/2.

# ---- http block: global SSL & session reuse --
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE+AESGCM:ECDHE+CHACHA20;
ssl_prefer_server_ciphers off; // 1.3 client chooses
ssl_session_cache  shared:SSL:20m;
ssl_session_timeout 1h;
ssl_session_tickets on;
# Multi-node must share same ticket key
ssl_session_ticket_key /etc/nginx/ticket.key;
ssl_ecdh_curve X25519:P-256;

# Session reuse is biggest gain beyond HTTP/2
# Verify: nginx -V confirm OpenSSL supports 1.3

# ---- server: default_server fallback ----
server {
    listen 443 ssl default_server;
    server_name _;
    ssl_certificate   /etc/nginx/a.pem;
    ssl_certificate_key /etc/nginx/a.key;
    return 444;  // silently drop non-SNI abuse
}
# ---- Production site ----
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    http2 on;         // 1.25.1+ syntax
    server_name a.com www.a.com;

    # Must be fullchain: leaf + intermediate
    ssl_certificate   /etc/nginx/a.pem;
    ssl_certificate_key /etc/nginx/a.key;
    # Verify: openssl s_client -showcerts

    # OCSP stapling: saves client one round-trip for revocation check
    ssl_stapling on;
    ssl_stapling_verify on;
    resolver 223.5.5.5 valid=300s;
    ssl_trusted_certificate /etc/nginx/ca.pem;

    add_header Strict-Transport-Security
    "max-age=15552000" always;
    add_header X-Content-Type-Options nosniff;
    add_header X-Frame-Options SAMEORIGIN;

    location / {
        proxy_pass http://web_pool;
    }
}

Three key choices explained:

ssl_prefer_server_ciphers off — TLS 1.3 suite order decided by client preference is better; server forcing order hurts performance. Only enable for specific old clients (e.g., Java 8u261 and earlier).

default_server uses return 444 — Non-SNI scanners/abuse silently dropped, cleaner than returning "cert mismatch".

ssl_trusted_certificate separate from ssl_certificate — Stapling verification needs full chain (including root), while client only needs leaf+intermediate; different purposes.

2.2 One HTTPS Request Timeline

T1: Client TCP SYN, server SYN+ACK, handshake done (1 RTT). T2: TLS ClientHello with SNI, Nginx selects server block's SSL_CTX by SNI. T3: ServerHello + cert chain + ECDHE params (TLS 1.3 completes key exchange here). T4: Client validates chain, computes session keys, sends Finished. T5: Server Finishes, encrypted channel established. T6: Client sends HTTP request, Nginx proxies upstream. T7: Upstream responds, Nginx encrypts back. Full: 2 RTTs for connection (TLS 1.3) or 3 RTTs (TLS 1.2), then 1 RTT per request . With session reuse, T2-T5 compressed to 1 RTT (TLS 1.2 abbreviated) or 0-RTT (TLS 1.3), cross-continent this alone saves ~100ms . Diagnose with curl -w splitting time_appconnect and time_starttransfer; difference = handshake time.

2.3 Complete Config 2: Kernel Parameters and File Descriptors

Below sysctl retains only items truly relevant to Nginx, each annotated with rationale and boundary— tuning principle: "know why before changing", not "longer checklist = more professional" :

# /etc/sysctl.d/99-nginx.conf
# 1. Connection queues: accept queue ceiling
net.core.somaxconn = 65535
# Half-open queue (SYN flood protection)
net.ipv4.tcp_max_syn_backlog = 65535
# 2. Ports & TIME_WAIT (critical for reverse proxy)
net.ipv4.ip_local_port_range = 10000 65000
net.ipv4.tcp_tw_reuse = 1 // only outbound
net.ipv4.tcp_max_tw_buckets = 262144
net.ipv4.tcp_fin_timeout = 15
# 3. File descriptor total
fs.file-max = 1048576
fs.nr_open  = 1048576
# 4. conntrack: table full = silent drop
net.netfilter.nf_conntrack_max = 1048576
net.netfilter.nf_conntrack_buckets = 262144
// hashsize = max/4
# 5. TCP memory three tiers (pages)
net.ipv4.tcp_mem = 786432 1048576 1572864
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
# File descriptors three layers: missing one = EMFILE
# 1) systemd unit (nginx.service)
[Service]
LimitNOFILE=1048576
# 2) /etc/security/limits.conf
nginx soft nofile 1048576
nginx hard nofile 1048576
# 3) Kernel ceiling
# fs.nr_open must >= above two

# Apply & verify
sysctl -p /etc/sysctl.d/99-nginx.conf
sysctl net.core.somaxconn
ss -lnt | grep 443  // check Send-Q=backlog
cat /proc/sys/fs/nr_open
dmesg | grep -i conntrack

Common boundary pitfalls:

tcp_tw_reuse only helps active connection initiator (outbound) , irrelevant for "passive accept Nginx"; real beneficiary is upstream long-connection closure local port reuse.

tcp_max_tw_buckets cannot be too small , few thousand forces TIME_WAIT recycle causing peer RST.

nf_conntrack_buckets recommended at max/4 , only raising max without buckets degrades hash to linked list, CPU spikes in softirq.

somaxconn raised must also check listen backlog , Nginx default 511; both take min—only tuning kernel without Nginx is wasted.

2.4 Certificate Automation and Renewal Discipline

Cert expiry is the dumbest yet most common HTTPS incident. Three disciplines:

Full auto-renewal — acme.sh or certbot renew hook runs nginx -s reload (Nginx supports zero-downtime cert reload), and hook success/failure fed to monitoring.

30-day advance alert — Use openssl x509 -enddate or monitoring probe to fetch expiry; 30 days warning, 7 days critical.

Immediate chain validation post-renewal — Automation most often fails by "renewed new cert but concatenation missed intermediate"; renewal pipeline final step must run openssl s_client -showcerts verification and report result.

Monitor expiry + validate chain + auto-reload, all three automated, cert incidents vanish.

2.5 Troubleshooting Command Set: Five Scenarios, Five Commands

Cert chain complete? — openssl s_client -connect a.com:443 -showcerts, count returned certs (should be 2: leaf+intermediate).

Which clients fail? — openssl s_client -tls1_2 force version, or test with Java keytool / curl separately.

Handshake latency? —

curl -o /dev/null -s -w "connect:%{time_connect} tls:%{time_appconnect} total:%{time_total}"

, TLS minus connect = handshake.

Session reuse working? — openssl s_client -reconnect twice, check second shows "Reused".

Kernel dropping packets? — nstat -az watch TcpExtListenDrops / TcpExtTCPBacklogDrop growth, dmesg for conntrack alerts, ss -s socket stats. These five cover 90% of HTTPS and kernel incident scenes.

Core Source Code: Four Key Logic Paths

3.1 How Certificate Chain Loads into SSL_CTX

// ngx_event_openssl.c simplified
// Read PEMs sequentially, first is leaf
for (i = 0; i < n; i++) {
    if (i == 0) {
        // Leaf cert + private key
        SSL_CTX_use_certificate(ctx, x);
        SSL_CTX_use_PrivateKey(ctx, pkey);
    } else {
        // Rest appended to chain
        SSL_CTX_add_extra_chain_cert(ctx, x);
    }
}
// Private key must match cert, else startup fails
if (!SSL_CTX_check_private_key(ctx)) error;

This explains two things: ① File order determines role — PEM first must be leaf, subsequent are intermediates; wrong order (e.g., intermediate first) makes "leaf treated as chain intermediate" causing validation failure. ② Appended chain certs unlimited but unnecessary — Sending root does no harm (client ignores root already in trust store), but each cert adds hundreds of bytes to handshake packet; standard practice: send only leaf+intermediate. Startup SSL_CTX_check_private_key validates key pairing; mismatch fails nginx -t, a good early gate.

3.2 SNI Callback: Selecting Cert by Domain

// ngx_http_ssl_module.c simplified
static int ssl_servername(ssl, ad, arg) {
    host = SSL_get_servername(ssl,
    TLSEXT_NAMETYPE_host_name);
    if (host == NULL) return OK; // no SNI
    // Look up host in server_names hash
    name = ngx_hash_find(&conf->hash, host);
    if (name == NULL) {
        // No match: fall to default_server
        return OK;
    }
    // Switch to that server's SSL_CTX
    SSL_set_SSL_CTX(ssl, name->ssl_ctx);
    return OK;
}

This is the code-level answer to "HTTPS can't use Host header for virtual hosting": Cert selection happens early in handshake, relying on plaintext SNI field; if client sends no SNI (old Java default, direct IP access), it falls to default_server . So on multi-site servers, default_server's cert should be broadest coverage (or self-signed placeholder), and cannot be expected to match all domains—this is root cause of "some clients report cert mismatch", not cert misconfiguration.

3.3 Session Cache and Ticket Dual Paths

ssl_session_cache shared:SSL:20m

uses "server stores state": handshake completes, session params (master secret, suite, time) written to shared-memory red-black tree; client receives a 32-byte Session ID ticket ; next connection presents ID, server looks up and reuses. But if load balancer routes to another machine (without shared cache), guaranteed miss . ssl_session_tickets uses "client stores state": server encrypts session params with ticket key, hands blob to client; next connection returns it for self-decrypt— as long as all nodes share same ticket key file, hit rate independent of which machine . Hence production enables both, and ticket key must be synced: cache hits fast but local only, ticket works cross-machine but depends on key consistency. Rotating key must retain old key for a while (Nginx supports multiple ssl_session_ticket_key), else rotation instantly invalidates all existing tickets.

3.4 listen backlog and somaxconn Intersection

Connection establishment has two queues: Half-open queue (received SYN, handshake incomplete, length governed by tcp_max_syn_backlog and somaxconn) and Full-open queue (handshake done, awaiting accept, length = min( listen backlog, somaxconn)). Nginx listen backlog defaults to 511, kernel somaxconn defaults to 4096 (newer distros)— min of both, so only tuning kernel without Nginx leaves actual queue at 511 . High-concurrency bursts show ss -lnt Send-Q (backlog) full, TcpExtListenDrops growing, client sees "connection timeout but server CPU low". This is another form of Article 01's "scaling ineffective" incident: queue is not capacity but config issue.

Advanced Topics: Six Accounts to Calculate Upfront

4.1 Four Categories of Certificate Failure Diagnosis

Cert issues always fall into these four, eliminate in order:

Incomplete chain — Partial client failures, openssl s_client -showcerts shows only one cert.

Domain mismatch — "certificate not valid for requested name", check SAN includes actual accessed domain (www vs apex difference).

Expired — "expired", check notAfter.

Untrusted — Self-signed or root not in trust store, common in internal/test envs.

Suggested troubleshooting order starts with chain : incomplete chain obscures other three errors; fix chain first then reassess.

4.2 Cipher Suite Compatibility Matrix

Disabling legacy protocols hits real client compatibility. Four categories to watch:

Java 8u261 and earlier default no TLS 1.3, some old versions restrict ECDHE suites; enabling only 1.3 kills old JDK clients.

Android 4.x (API<20) no TLS 1.2; banking/gov scenarios needing these devices must keep 1.0 accepting compliance risk.

Mini-programs and iOS require TLS 1.2+ with complete chain, must support ATS suites (ECDHE+AESGCM)—essentially modern config defaults.

Legacy IoT and crawlers may only speak TLS 1.0 without SNI; returning 444 makes them disappear—if they are partners, must keep a compat entry in default_server.

Correct compatibility decision: first examine access log SSL version distribution ( $ssl_protocol and $ssl_cipher logged), don't guess.

4.3 Three OCSP Stapling Pitfalls

OCSP stapling lets server fetch revocation status for client and send with handshake, saving one external request and protecting privacy.

Pitfall 1: Must configure resolver — Nginx must resolve OCSP responder address; without resolver, stapling silently disabled.

Pitfall 2: ssl_trusted_certificate must be full chain — Verifying OCSP response needs issuer chain; leaf-only fails.

Pitfall 3: Internal network without egress causes stapling to persistently fail — Manifests as slightly slower handshake but functional (stapling is best-effort); don't mistake its alerts for cert failure. Verify: openssl s_client -status -connect a.com:443, check output for "OCSP Response Status: successful".

4.4 HSTS Irreversibility Risk

HSTS tells browser "this domain only HTTPS from now on", once browser remembers, cannot fall back to HTTP until max-age expires . Two real risks: ① Cert issue blocks users entirely (browser offers no "proceed anyway"), if you revert site to HTTP for emergency, old users still locked out. ② Preload list hardcoded into browsers; removal takes months or longer. Rollout cadence: start max-age=300 observe week → gradually raise to day, month → stable then 6 months → only then consider preload (and confirm all subdomains have HTTPS). HSTS has clear benefit but hard rollback; always start with small steps.

4.5 Three Kernel Tuning Disciplines

Only tune parameters matching observed symptoms — ListenDrops → tune queues; conntrack full → tune table; EMFILE → tune fds; no symptom → don't touch.

Change one group at a time with observation window — Changing ten at once makes root-cause impossible; observe at least one business peak after each change.

Parameters under version control — /etc/sysctl.d/ files in git and config management, so server rebuild doesn't lose them; "manual sysctl -w effective but not persisted" is classic ops trap (reboot reverts, incident unreproducible). Also note: container environments isolate many net.* params per namespace; changing inside Pod may not affect host, and vice versa; K8s requires initContainer or securityContext to set explicitly.

4.6 Full-Path Latency Accounting: Calculate RTT Clearly

One cross-continent HTTPS request (RTT 200ms, TLS 1.2 no reuse): TCP handshake 1 RTT = 200ms, TLS handshake 2 RTT = 400ms, HTTP request/response 2 RTT = 400ms, TTFB ~1 second, of which 600ms purely connection setup . With TLS 1.3 + session reuse: TCP 1 RTT + TLS 1 RTT (or 0-RTT) + data 2 RTT ≈ 600-800ms. Add CDN for static assets (edge RTT 20ms) + HTTP/2 connection reuse, first screen drops to 200ms level. This accounting explains why "stronger CPU" barely helps; "reducing RTT rounds" is HTTPS optimization mainline —protocol version, session reuse, CDN edge, connection reuse all reduce round-trips; none increase compute power.

Learning Path: From "It Runs" to "I Can Tune"

Master certificate chain : Use openssl to manually validate three-layer chain from a leaf, deliberately delete intermediate to reproduce "PC OK App fails"; you'll never forget this pit.

Quantify handshake cost : Benchmark HTTPS with ab/wrk, compare QPS and CPU with session_cache on/off, use curl -w to extract time_appconnect, turn "how much is handshake" into your own numbers.

Read two module docs and source : Go through all ngx_http_ssl_module directives, read ngx_event_openssl.c functions around ssl_handshake and session cache, understand SNI callback and ticket decryption locations.

Do a kernel health check : Apply only items from 2.3 matching your machine's symptoms, use nstat/ss/dmesg trio to establish baseline, turn "tuning" from copying checklists into reading metrics.

High-Frequency Interview Questions (with Answers)

Q1: Why must server send full cert chain? A: Client only has root in trust store; needs intermediate to bridge root→leaf. Browsers have AIA to auto-fetch intermediate; Apps, Java, IoT usually don't—missing chain fails handshake. Server should send leaf+intermediate, not root.

Q2: How does HTTPS support multiple domains on one machine? A: Via SNI: ClientHello carries plaintext domain; Nginx in ngx_http_ssl_servername callback looks up domain in server_names hash, switches to matching SSL_CTX. HTTP uses Host header for virtual host, but HTTPS cert selection happens before Host header exists.

Q3: What happens if client sends no SNI? A: Falls to default_server, receives its cert, likely mismatches accessed domain. So default_server must be explicitly configured (often broadest cert or return 444), else first loaded server block becomes fallback.

Q4: How many RTTs for TLS handshake? Where is 1.3 faster? A: TLS 1.2 full handshake 2 RTT; 1.3 only 1 RTT (key exchange moved to first flight); session reuse can drop to 0-RTT. 0-RTT has replay risk, only for idempotent requests.

Q5: After switching to HTTPS QPS halves, what to check first? A: Check session reuse: is ssl_session_cache configured shared? ssl_session_tickets on? Multi-node ticket key consistent? TLS overhead mainly in handshake; low reuse = every request does a signature op.

Q6: Difference between session cache and session ticket? A: Cache = server stores state (client presents Session ID), only valid locally, multi-node needs sharing; Ticket = server encrypts state, client stores it, any node with same ticket key works. Production enables both.

Q7: ECDHE vs RSA key exchange difference? A: RSA encrypts pre-master with cert public key, no forward secrecy if private key leaks; ECDHE both sides contribute ephemeral params, provides forward secrecy, and performs better. Modern config keeps only ECDHE suites, disables RSA key exchange and CBC modes.

Q8: Should ssl_prefer_server_ciphers be on or off? A: Default recommend off—TLS 1.3 client-chosen suites perform better (client knows its AES-NI/hardware acceleration). Only on for old clients requiring specific suite order.

Q9: Why does raising somaxconn still drop connections? A: Full queue length = min(listen backlog, somaxconn). Nginx listen default backlog 511; only tuning kernel leaves actual queue at 511. Both must be raised; watch ss -lnt Send-Q and TcpExtListenDrops.

Q10: What does tcp_tw_reuse do? Can it solve server TIME_WAIT? A: Only helps active connection initiator (outbound), reuses local ports in TIME_WAIT. Nginx as reverse proxy connecting upstream benefits; as passive server accepting connections, irrelevant. Server side should use long connections and widen port range.

Q11: Why must tcp_tw_recycle not be enabled? A: It uses timestamps to judge connection age; under NAT (multiple clients share IP, timestamps unsynced) it drops seemingly "stale" connections causing random connect failures. Parameter removed after Linux 4.12; seeing it in a checklist indicates that list is outdated.

Q12: How to handle nf_conntrack: table full? A: Table full = silent drop. Raise nf_conntrack_max, simultaneously set hashsize (buckets) to max/4, else hash degrades to linked list spiking softirq CPU; also reduce short connections from business side, shorten UDP session timeout.

Q13: Which layers to check for "too many open files"? A: Three layers, none missing: systemd unit LimitNOFILE, limits.conf soft/hard, fs.nr_open kernel ceiling (must be ≥ previous two). Also worker_rlimit_nofile and worker_connections must match.

Q14: Three prerequisites for OCSP stapling? A: Configure resolver (Nginx resolves OCSP URL), ssl_trusted_certificate with full chain (verify response), server has internet egress. Internal no-egress: stapling silently fails but handshake works.

Q15: HSTS risks? How to roll out? A: Browser remembers, cannot fallback to HTTP within max-age; cert failure blocks users completely; preload even more irreversible. Rollout: 300s observe → gradually increase → stable at 6 months → confirm all subdomains HTTPS before preload.

Q16: How does HTTP/2 affect rate limiting? A: Single connection multiplexing weakens limit_conn (one connection carries dozens of streams); must use limit_req by request count, plus http2_max_concurrent_streams to cap streams per connection.

Q17: Quick verify cert chain complete and session reuse? A: Chain: openssl s_client -connect a.com:443 -showcerts count certs (should be 2). Reuse: openssl s_client -reconnect check second shows "Reused". Latency: curl -w split time_connect and time_appconnect.

Q18: Does PEM file cert order matter? A: Yes. First must be leaf (Nginx loads first as leaf and pairs with private key), subsequent are intermediates. Wrong order breaks validation chain or causes private key mismatch startup failure.

Q19: Correct kernel tuning workflow? A: Symptom first (ListenDrops/conntrack full/EMFILE) → tune only corresponding group → observe one business peak → persist to /etc/sysctl.d and version control. Forbid copying checklists batch changes, forbid sysctl -w without persistence.

Q20: What is HTTPS optimization mainline? A: Reduce RTT rounds, not increase compute: TLS 1.3 (saves 1 RTT), session reuse (saves 1-2 RTT), CDN edge (shortens RTT), HTTP/2 connection reuse (avoids repeated connection setup). All four reduce round-trips; CPU upgrade barely felt.

One-Page Cheat Sheet

Cert : Send leaf+intermediate, not root; PEM first must be leaf; missing chain browsers auto-fix, Apps don't. SNI : Uses ClientHello plaintext domain to select cert; must configure default_server fallback. Protocol : 1.2+1.3, only ECDHE+AESGCM/CHACHA20, disable CBC and RSA key exchange. Reuse : session_cache shared + tickets, multi-node share ticket key; reuse rate is HTTPS performance #1 metric. Kernel four groups : Queues (somaxconn and listen backlog take min), Ports & TIME_WAIT (tw_reuse only outbound), FD three layers, Conntrack (max and buckets ratio). Taboos : Never enable tw_recycle, max_tw_buckets not too small, copying sysctl checklist guarantees incidents. Optimization mainline : Reduce RTT, not swap CPU.

Summary and Next Episode Preview

HTTPS and kernel layers share a trait: Misconfiguration doesn't fail immediately; it explodes only at certain client types or traffic inflection points . Missing one cert in chain—browser tests forever pass; session reuse off—low concurrency tests forever pass; conntrack table small—normal times forever pass. So this article's landing point isn't "memorize a few parameters" but remember three things: Trust chain must close loop, handshakes must be amortized, kernel must be tuned against symptoms . Next episode enters core troubleshooting toolchain: logs and packet capture—difference between $request_time and $upstream_response_time, semantics of five timeout variables, how to locate a single chain from client to upstream, and how to design production log format.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

nginxLinux kernelTLSHTTPSOCSP staplingsession reusekernel tuningcertificate chain
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.