0
0
Nginxdevops~5 mins

SNI for multiple SSL certificates in Nginx - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: SNI for multiple SSL certificates
O(n)
Understanding Time Complexity

We want to understand how the time to handle SSL connections changes when using multiple certificates with SNI in nginx.

How does nginx manage multiple SSL certificates as the number of domains grows?

Scenario Under Consideration

Analyze the time complexity of the following nginx configuration snippet using SNI.


server {
    listen 443 ssl;
    server_name example.com;
    ssl_certificate /etc/ssl/example.com.crt;
    ssl_certificate_key /etc/ssl/example.com.key;
}

server {
    listen 443 ssl;
    server_name example.org;
    ssl_certificate /etc/ssl/example.org.crt;
    ssl_certificate_key /etc/ssl/example.org.key;
}

# ... more server blocks for other domains

This config uses SNI to serve different SSL certificates based on the requested domain.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: nginx matches the requested domain against server blocks to select the correct SSL certificate.
  • How many times: This matching happens once per new SSL connection during the handshake.
How Execution Grows With Input

As the number of server blocks (domains) increases, nginx must check more entries to find the right certificate.

Input Size (n)Approx. Operations
10About 10 domain checks per connection
100About 100 domain checks per connection
1000About 1000 domain checks per connection

Pattern observation: The number of checks grows roughly in direct proportion to the number of configured domains.

Final Time Complexity

Time Complexity: O(n)

This means the time to select the SSL certificate grows linearly with the number of domains configured.

Common Mistake

[X] Wrong: "nginx instantly finds the right certificate no matter how many domains there are."

[OK] Correct: nginx checks server blocks one by one until it finds a match, so more domains mean more checks.

Interview Connect

Understanding how nginx handles multiple SSL certificates helps you explain real-world server performance and scaling in interviews.

Self-Check

"What if nginx used a hash map to store domain-to-certificate mappings? How would the time complexity change?"