{"id":1778,"date":"2026-11-18T22:21:43","date_gmt":"2026-11-18T22:21:43","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=1778"},"modified":"2026-11-18T22:21:43","modified_gmt":"2026-11-18T22:21:43","slug":"ktls-vps-nginx-tls-offload-measurement","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/ktls-vps-nginx-tls-offload-measurement\/","title":{"rendered":"In-Kernel TLS (kTLS) on a VPS: Offloading Nginx TLS Without a NIC IPsec Helper"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">kTLS \u2014 kernel TLS \u2014 moves the record-layer encryption and decryption of a TLS connection from userspace into the Linux kernel socket layer. Nginx 1.21.4 and later can enable it with <code>ssl_conf_command Options KTLS;<\/code>, and on a VPS with an AES-NI capable CPU this removes two copies of every record and lets the kernel hand pages directly to the NIC or the receiving socket. The gain is real but modest, and it is easy to measure wrongly by comparing the wrong TLS version or the wrong cipher.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This article sets up kTLS on Nginx, confirms the kernel path is actually taken, and benchmarks it against userspace OpenSSL with a method that isolates the TLS layer. If you have not yet sized the instance, the CPU and disk baselines in <a href=\"https:\/\/virtualserversvps.com\/\">our VPS performance guides<\/a> are the right starting point.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Check that the kernel supports kTLS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">kTLS has been in mainline since 4.13 and the software crypto fallback since 5.1. Both TX and RX offload paths are registered against the cipher implementation, so the first thing to confirm is which ciphers the running kernel exposes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep TLS \/boot\/config-$(uname -r)\ncat \/proc\/crypto | awk '\/^name\/ {n=$3} \/^type\/ {t=$3} \/^driver\/ {d=$3}\n  n ~ \/tls\/ &amp;&amp; t == \"skcipher\" {print n, d}' | sort -u\nopenssl version -a | head -3\nnginx -V 2&gt;&amp;1 | tr ' ' '\\n' | grep -i ssl<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You want to see <code>tls12_aes_gcm_256<\/code>, <code>tls12_aes_gcm_128<\/code> and ideally <code>aesni_intel<\/code> as the driver. The AES-CCM variants exist but are rarely negotiated. ChaCha20-Poly1305 has a kTLS implementation too, but it only helps when the CPU lacks AES-NI; on any modern Xeon or EPYC, AES-GCM is faster and you should benchmark with that.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Enable kTLS in Nginx without breaking the config<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Add the directive inside a server block that already has HTTP\/2 or TLS 1.3 configured. Note that as of Nginx 1.25, kTLS is supported for TLS 1.2 and TLS 1.3 on Linux; the directive silently degrades if the kernel lacks the cipher, which is a useful failure mode but also means you must verify rather than assume.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server {\n  listen 443 ssl;\n  http2 on;\n  server_name example.test;\n\n  ssl_certificate     \/etc\/ssl\/fullchain.pem;\n  ssl_certificate_key \/etc\/ssl\/privkey.pem;\n  ssl_protocols       TLSv1.2 TLSv1.3;\n  ssl_ciphers         TLS_AES_256_GCM_SHA384:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES256-GCM-SHA384;\n  ssl_conf_command    Options KTLS;\n\n  location \/ { root \/srv\/www; }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Reload with <code>nginx -t &amp;&amp; systemctl reload nginx<\/code>, then confirm from the outside that the negotiated cipher is AES-GCM. If the client falls back to ChaCha20 the kTLS TX path still works but the performance story changes, and you will have benchmarked a different configuration than you think.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Confirm kTLS is actually engaged<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Two independent checks are worth doing. The first is <code>ss<\/code>, which reports TLS information on established sockets. The second is the kernel&#8217;s crypto accounting, which increments per-cipher request counters only when the kernel is doing the work.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ss -ti '( sport = :443 )' | head -20\n# Look for \"tls12_aes_gcm_256\" in the socket info block\ncat \/proc\/crypto | awk '\/tls12_aes_gcm_256\/{f=1} f&amp;&amp;\/^[a-z]\/ {print} \/^$\/{if(f)exit}'\n# Per-CPU TLS counters (kernel 5.15+)\ngrep -i tls \/proc\/net\/tls_stat 2&gt;\/dev\/null || echo \"tls_stat not present\"\nstrace -f -e trace=setsockopt -p $(pgrep -o nginx) 2&gt;&amp;1 | grep -i ktls | head<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>ss<\/code> line is the most reliable: a socket showing <code>tls12_aes_gcm_256<\/code> is a kernel-offloaded socket. If the socket shows only congestion-control detail and no cipher name, Nginx accepted the directive but the kernel path was not entered \u2014 usually because the cipher chosen by the client is not the one listed in <code>\/proc\/crypto<\/code>, or because the Nginx build lacks <code>--with-openssl<\/code> support for the option.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Benchmark the TLS layer in isolation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Do not benchmark with <code>wrk<\/code> against a dynamic page; you will measure PHP, not TLS. Serve a 1 MB static file and hammer it with keepalive connections so the handshake cost is amortised and the record path dominates.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>head -c 1048576 \/dev\/urandom &gt; \/srv\/www\/1m.bin\nwrk -t4 -c128 -d60s --latency \\\n  --header 'Host: example.test' https:\/\/127.0.0.1\/1m.bin\n# CPU split: kernel vs userspace during the run\npidstat -p $(pgrep -o nginx) 1 30 | awk '{print $1, \"usr=\"$4, \"sys=\"$5}'<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Run the same test with <code>ssl_conf_command Options KTLS;<\/code> commented out. The total request rate typically moves by 5\u201320% depending on payload size; the more interesting number is the <code>sys<\/code> versus <code>usr<\/code> split. With kTLS the userspace share drops sharply because OpenSSL stops doing the bulk work per record \u2014 the CPU time moves into the kernel sendfile path but total CPU per byte should fall.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Watch for the cases where kTLS does not help<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Three conditions routinely erase the gain. First, small responses: if your median response is 2 KB, the per-record overhead dominates and the copy elimination is worth almost nothing. Second, TLS termination in front of dynamic app servers where the bottleneck is PHP-FPM or the database \u2014 the TLS layer may be under 5% of total CPU. Third, hosts where AES-NI is masked and you fall back to the generic AES implementation, in which case OpenSSL&#8217;s hand-tuned assembly may actually beat the kernel path.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Verify AES-NI is visible inside the guest with <code>grep -o aes \/proc\/cpuinfo | head -1<\/code>. If it is missing, stop and fix that first \u2014 it is worth an order of magnitude more than any TLS offload setting. When you are ready to size the plan around real TLS throughput rather than guesses, <a href=\"https:\/\/virtualserversvps.com\/\">compare VPS plans<\/a> with the benchmark numbers in hand.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A measurement checklist you can re-run<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Keep one script that prints the negotiated cipher, the <code>ss<\/code> socket line, and the wrk result for both configurations. Run it after every Nginx upgrade, because the directive&#8217;s behaviour has changed more than once and a silent regression is easy to miss. Record the payload size alongside the request rate.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The honest conclusion is that kTLS is a free 5\u201315% on static-heavy TLS workloads and approximately nothing elsewhere. It costs one directive and one verification step, so it is worth enabling \u2014 but it is not a substitute for fixing application-side CPU or sizing the instance correctly, and the measurement discipline above is what keeps it from becoming cargo-cult configuration.<\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>kTLS \u2014 kernel TLS \u2014 moves the record-layer encryption and decryption of a TLS connection from userspace into the Linux kernel socket layer. Nginx 1.21.4 and later can enable it&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":2,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1778","post","type-post","status-publish","format-standard","hentry","category-performance-optimization"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>In-Kernel TLS (kTLS) on a VPS: Offloading Nginx TLS Without a NIC IPsec Helper - Virtual Servers VPS Blog<\/title>\n<meta name=\"description\" content=\"kTLS \u2014 kernel TLS \u2014 moves the record-layer encryption and decryption of a TLS connection from userspace into the Linux kernel socket layer. Nginx 1.21.4\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/virtualserversvps.com\/blog\/ktls-vps-nginx-tls-offload-measurement\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"In-Kernel TLS (kTLS) on a VPS: Offloading Nginx TLS Without a NIC IPsec Helper\" \/>\n<meta property=\"og:description\" content=\"In-Kernel TLS (kTLS) on a VPS: Offloading Nginx TLS Without a NIC IPsec Helper\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/ktls-vps-nginx-tls-offload-measurement\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-18T22:21:43+00:00\" \/>\n<meta name=\"author\" content=\"Virtual-Servers-Vps-Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virtual-Servers-Vps-Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/ktls-vps-nginx-tls-offload-measurement\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/ktls-vps-nginx-tls-offload-measurement\/\",\"name\":\"In-Kernel TLS (kTLS) on a VPS: Offloading Nginx TLS Without a NIC IPsec Helper - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-11-18T22:21:43+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"description\":\"kTLS \u2014 kernel TLS \u2014 moves the record-layer encryption and decryption of a TLS connection from userspace into the Linux kernel socket layer. Nginx 1.21.4\",\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/ktls-vps-nginx-tls-offload-measurement\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/ktls-vps-nginx-tls-offload-measurement\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/ktls-vps-nginx-tls-offload-measurement\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"In-Kernel TLS (kTLS) on a VPS: Offloading Nginx TLS Without a NIC IPsec Helper\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/\",\"name\":\"Virtual Servers VPS Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\",\"name\":\"Virtual-Servers-Vps-Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"caption\":\"Virtual-Servers-Vps-Editor\"},\"sameAs\":[\"https:\/\/virtualserversvps.com\/blog\"],\"url\":\"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"In-Kernel TLS (kTLS) on a VPS: Offloading Nginx TLS Without a NIC IPsec Helper - Virtual Servers VPS Blog","description":"kTLS \u2014 kernel TLS \u2014 moves the record-layer encryption and decryption of a TLS connection from userspace into the Linux kernel socket layer. Nginx 1.21.4","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/virtualserversvps.com\/blog\/ktls-vps-nginx-tls-offload-measurement\/","og_locale":"en_US","og_type":"article","og_title":"In-Kernel TLS (kTLS) on a VPS: Offloading Nginx TLS Without a NIC IPsec Helper","og_description":"In-Kernel TLS (kTLS) on a VPS: Offloading Nginx TLS Without a NIC IPsec Helper","og_url":"https:\/\/virtualserversvps.com\/blog\/ktls-vps-nginx-tls-offload-measurement\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-11-18T22:21:43+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/ktls-vps-nginx-tls-offload-measurement\/","url":"https:\/\/virtualserversvps.com\/blog\/ktls-vps-nginx-tls-offload-measurement\/","name":"In-Kernel TLS (kTLS) on a VPS: Offloading Nginx TLS Without a NIC IPsec Helper - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-11-18T22:21:43+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"description":"kTLS \u2014 kernel TLS \u2014 moves the record-layer encryption and decryption of a TLS connection from userspace into the Linux kernel socket layer. Nginx 1.21.4","breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/ktls-vps-nginx-tls-offload-measurement\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/ktls-vps-nginx-tls-offload-measurement\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/ktls-vps-nginx-tls-offload-measurement\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"In-Kernel TLS (kTLS) on a VPS: Offloading Nginx TLS Without a NIC IPsec Helper"}]},{"@type":"WebSite","@id":"https:\/\/virtualserversvps.com\/blog\/#website","url":"https:\/\/virtualserversvps.com\/blog\/","name":"Virtual Servers VPS Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0","name":"Virtual-Servers-Vps-Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","caption":"Virtual-Servers-Vps-Editor"},"sameAs":["https:\/\/virtualserversvps.com\/blog"],"url":"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/"}]}},"_links":{"self":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1778","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/comments?post=1778"}],"version-history":[{"count":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1778\/revisions"}],"predecessor-version":[{"id":1780,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1778\/revisions\/1780"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=1778"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=1778"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=1778"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}