Optimizing SSL/TLS Performance: When and How to Use ssl_session_cache in Nginx Configuration


9 views

When configuring HTTPS in Nginx, the ssl_session_cache directive plays a crucial role in optimizing TLS handshake performance. This mechanism stores SSL/TLS session parameters to enable session resumption, significantly reducing computational overhead for subsequent connections.

Implementing ssl_session_cache provides several advantages:

  • Reduces full TLS handshakes by up to 50%
  • Decreases CPU usage for encryption operations
  • Improves connection establishment time
  • Lowers latency for returning visitors

Here's a recommended Nginx configuration snippet:

ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_session_tickets off;

For high-traffic servers, consider increasing the cache size:

ssl_session_cache shared:SSL:50m;
ssl_session_timeout 4h;

You should strongly consider SSL session caching when:

  • Your server handles over 100 HTTPS requests per second
  • Client connections frequently reconnect (e.g., mobile apps)
  • You're using computationally expensive cipher suites
  • Server resources are constrained

Check your cache performance using:

nginx -V 2>&1 | grep -o with-http_stub_status_module
# Then configure status endpoint:
location /nginx_status {
    stub_status;
    allow 127.0.0.1;
    deny all;
}

Look for session cache hits in your monitoring tools to verify proper configuration.

For distributed systems, combine with:

ssl_session_cache shared:SSL:100m;
ssl_buffer_size 4k;
ssl_session_tickets on;

Remember that session tickets (RFC 5077) may provide better performance than traditional caching in some scenarios.


Every HTTPS connection begins with an SSL/TLS handshake - a computationally expensive process that establishes secure session parameters. For high-traffic websites, this initial negotiation can become a significant performance bottleneck.

Nginx's ssl_session_cache stores session parameters after the first connection, allowing subsequent connections from the same client to bypass the full handshake using a simplified session resumption process. This typically reduces connection setup time by 30-50%.

ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;

Consider implementing session caching when:

  • Your server handles >100 HTTPS requests per second
  • Clients make multiple sequential requests (common in SPA applications)
  • You observe high CPU usage during SSL handshakes
  • Mobile clients with high latency connections are predominant

For optimal performance:

# Shared cache across worker processes (1MB can store ~4000 sessions)
ssl_session_cache shared:SSL:10m;

# Session ticket lifetime (balance security vs performance)
ssl_session_timeout 4h;

# Enable stateless session tickets (works better with load balancers)
ssl_session_tickets on;

Use these metrics to validate your configuration:

# Check session reuse rate
openssl s_client -connect example.com:443 -reconnect -no_ticket 2>&1 | grep "Reused"

# Monitor cache hits in Nginx
nginx -V 2>&1 | grep -o with-http_stub_status_module
# Then check status page for cache statistics

While session caching improves performance:

  • Shorter timeouts (1-4 hours) balance security and performance
  • Rotate ticket keys periodically for forward secrecy
  • Disable caching for highly sensitive applications