Skip to content

Instantly share code, notes, and snippets.

@holmberd
Last active February 21, 2023 01:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holmberd/fa87e5f505e04a378ccf9a7b59456e8c to your computer and use it in GitHub Desktop.
Save holmberd/fa87e5f505e04a378ccf9a7b59456e8c to your computer and use it in GitHub Desktop.
How Nginx determines which SSL certificate to use for multiple domains pointing at a single IP

How Nginx determines which server block to route the request through.

Nginx tests only the request’s header field Host to determine which server the request should be routed to. If its value does not match any server name, or the request does not contain this header field at all, then nginx will route the request to the default server, the first server block if no default is specified, or determine the default alphabetical order.

How does TLS SNI help to determine which SSL certificate to use.

TLS does not provide a mechanism for a client to tell a server the name of the server it is contacting. It may be desirable for clients to provide this information to facilitate secure connections to servers that host multiple 'virtual' servers at a single underlying network address.

TLS Server Name Indication extension, allows a browser to pass a requested server name during the SSL handshake and, therefore, the server will know which certificate it should use for the connection.

A SSL connection to your server is established by SSL Handshake before the browser sends an HTTP request. Since this handshake takes place before the HTTP request containing the host header is sent, Nginx can't use the server name passed over SNI to determine which server block's SSL certificate to use for the handshake. It will either use the SSL certificate from the default block or from the HTTP block. If the SSL certificate file in the HTTP block contains multiple domain names (SAN), the server name passed through with SNI enabled will help determine which certificate to use for the handshake.

Refs:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment