Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Why Nginx Slows Down After Enabling SSL and How to Fix It

· 5 min read · Home Tech

In this article
  1. What Actually Happens When You Enable SSL
  2. Key Causes of SSL Slowdown
  3. How to Fix the Slowdown (Step-by-Step)
  4. Common Mistakes That Make It Worse
  5. Measuring the Impact
  6. When the Slowdown Is Not SSL Itself
  7. Frequently Asked Questions

Enabling SSL/TLS on nginx can noticeably increase response times, often by 10–50% for small requests, due to the extra handshake and encryption overhead. The slowdown is usually caused by missing session resumption, weak cipher choices, or lack of hardware acceleration, and can be fixed with a few configuration tweaks and modern TLS settings.

What Actually Happens When You Enable SSL

When a client connects over HTTPS, nginx must perform a TLS handshake before any HTTP data is exchanged. This handshake involves several round trips (TLS 1.2 typically takes two, TLS 1.3 takes one) and expensive cryptographic operations like RSA or ECDHE key exchange. For a single request, the added latency is often just a few milliseconds, but for high-traffic sites with many new connections, the cumulative CPU cost and extra round trips can make the server feel sluggish.

The slowdown is most noticeable for small requests (like API calls or page assets) because the handshake time is a large fraction of the total time. For large downloads, the encryption overhead is relatively small. Also, if your server uses older CPUs without AES-NI, encrypting every byte can become a bottleneck.

Key Causes of SSL Slowdown

  • No session resumption: Every new connection requires a full handshake unless you enable session tickets or session cache.
  • Weak cipher suites: Using old ciphers like RC4 or 3DES forces slower, less efficient encryption.
  • Large certificate chains: Sending multiple certificates (e.g., intermediate and root) increases handshake size and latency.
  • Lack of OCSP stapling: Without it, clients must fetch certificate revocation status separately, adding an extra request.
  • Old TLS versions: TLS 1.2 is slower than TLS 1.3 due to more round trips and less efficient key exchange.
  • Software encryption: If your server CPU lacks AES-NI, encryption is done in software, which is much slower.

How to Fix the Slowdown (Step-by-Step)

  1. Enable TLS 1.3 – In your server block, set ssl_protocols TLSv1.2 TLSv1.3; (TLS 1.3 is enabled by default in nginx 1.13.0+).
  2. Enable session resumption – Add ssl_session_cache shared:SSL:10m; and ssl_session_timeout 10m; to cache session parameters. For better performance, also enable ssl_session_tickets on; (default is on, but verify).
  3. Use modern cipher suites – Set ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384'; and ssl_prefer_server_ciphers off; to let the client choose the best.
  4. Enable OCSP stapling – Add ssl_stapling on; and ssl_stapling_verify on; (requires a valid certificate chain).
  5. Optimize certificate chain – Ensure you send only the necessary intermediate certificates, not the root. Use a tool like openssl s_client to check.
  6. Enable HTTP/2 – Add listen 443 ssl http2; to reduce latency through multiplexing.
  7. Consider hardware acceleration – If your CPU supports AES-NI, nginx uses it automatically. For very high traffic, consider a dedicated TLS terminator or a load balancer with hardware offload.

Common Mistakes That Make It Worse

  • Disabling session cache – Some guides suggest turning it off for security, but for most sites the risk is minimal and the performance hit is significant.
  • Using a huge certificate chain – Including the root certificate adds unnecessary bytes to every handshake.
  • Keeping TLS 1.0/1.1 enabled – These old versions are slow and insecure; they also force clients to use older, slower ciphers.
  • Not using HTTP/2 – Without it, each asset requires a separate connection, multiplying handshake overhead.
  • Ignoring TCP settings – Enabling tcp_nodelay and tcp_nopush appropriately can reduce latency and packet overhead.

Measuring the Impact

Before making changes, benchmark your site with tools like ab (ApacheBench) or wrk to see the current requests per second and latency. After applying the fixes, run the same test and compare. A typical improvement is 20–40% reduction in handshake time and a 10–20% increase in throughput for small requests. For a single user, the difference may be imperceptible, but for high-traffic servers it can be substantial.

Also, use browser developer tools to check the “Connection” timing. If you see a long “TLS handshake” time, that confirms the issue.

When the Slowdown Is Not SSL Itself

Sometimes the slowdown is not the encryption but the configuration around it. For example, if you have ssl_session_cache disabled, every request triggers a full handshake, which is especially costly for mobile clients on high-latency networks. Also, if you are using a very large Diffie-Hellman parameter file (e.g., 4096-bit) for DHE ciphers, the key exchange can be extremely slow. Switching to ECDHE (Elliptic Curve Diffie-Hellman) eliminates this because it uses smaller keys with equivalent security.

Another common issue is that nginx is compiled without TLS 1.3 support. Check with nginx -V to see if it includes --with-http_ssl_module and the OpenSSL version. If your OpenSSL is older than 1.1.1, TLS 1.3 is not available.

Frequently Asked Questions

Why is HTTPS slower than HTTP?

HTTPS requires a TLS handshake that adds one or two round trips and CPU-intensive cryptographic operations. For small requests, this overhead is significant, but for large transfers, the difference is minimal. With session resumption and TLS 1.3, the overhead is reduced to near zero for repeat connections.

Does enabling SSL affect SEO or ranking?

Google has stated that HTTPS is a ranking signal, so the slight performance cost is usually worth it. However, if your site becomes significantly slower, that could hurt user experience and indirectly affect rankings. The fixes above keep the performance impact negligible.

Should I use a CDN or reverse proxy to offload SSL?

Yes, a CDN or reverse proxy can terminate TLS closer to the user and reduce load on your origin server. This is a common practice for high-traffic sites, but it adds a third-party dependency. For most small and medium sites, the nginx tweaks above are sufficient.

What is the best cipher suite for nginx?

The best ciphers are those that support forward secrecy and are fast on modern hardware. ECDHE with AES-GCM is the standard choice. ChaCha20-Poly1305 is better for mobile devices without AES hardware acceleration. You can use the list provided in the steps above, which is based on Mozilla's recommended configuration.

Does enabling HTTP/2 help with SSL performance?

Yes, HTTP/2 reduces the number of connections needed and allows multiplexing, which reduces the impact of handshake latency. It also uses header compression, which reduces overhead. Enabling it is a simple one-line change and is highly recommended.

Can I disable SSL for some pages to speed up the site?

Technically yes, but it's a bad practice. Mixed content warnings, security risks, and SEO issues outweigh any performance gain. Instead, optimize your SSL configuration as described above.