$ssl_server_name

The variable $ssl_server_name contains the name of the server specified with the 'server_name' directive that matches a request during SSL handshake. — NGINX Core (HTTP)

$ssl_server_name NGINX Core (HTTP)

Description

The variable $ssl_server_name is set within the context of an SSL-enabled NGINX server block and is primarily utilized to identify which virtual server is serving a request based on its server name during the SSL handshake phase. When a client initiates an SSL connection to the NGINX server, the server evaluates the requested hostname against the configured 'server_name' directives of each server block. The first matching server is used, and its corresponding server name is stored in the $ssl_server_name variable. In the case where there is no matching server name found, $ssl_server_name will be empty, and the default server's name (if configured) might be used instead. This variable behaves similarly to $server_name; however, it is specifically populated during the SSL handshake process, allowing it to be utilized for various purposes such as logging, access control, and generating responses based on the requested hostname. Typical values for $ssl_server_name would be the DNS names configured in the server blocks, such as 'example.com' or 'www.example.com'.

Config Example

server {
    listen 443 ssl;
    server_name example.com www.example.com;
    ssl_certificate /path/to/cert.pem;
    ssl_certificate_key /path/to/key.pem;
    location / {
        add_header X-SSL-Server-Name "$ssl_server_name";
    }
}

Subsystem

http

Cacheable

Yes

Contexts

http, server, location, if

Ensure that SSL is enabled for the server block using 'listen 443 ssl;'.

If there is no matching server_name, the variable will be empty; be cautious during server configuration to avoid confusion.

$ssl_server_name cannot be used within configurations that are not related to SSL. Make sure the context is appropriate.