March 29, 2021

Several HTTPS servers on a single Nginx instance

To run several HTTPS servers on the same IP address and same Nginx instance, just use Nginx with enabled SNI support. SNI stays for Server Name Indication, an extension of TLS protocol. More about SNI, more about SNI support in Nginx.

If Nginx supports SNI, it is enough to configure a separate server section for each domain with its SSL-certificates (or with a multidomain certificate for all configured domain names):

# Configuration for the 1st server www.example.dev
server {
    listen              80;
    listen              443 ssl;
    server_name         www.example.dev;
    ssl_certificate     www.example.dev.crt;
    ssl_certificate_key www.example.dev.key;
    ...
}

# Configuration for the 2nd server www.beispiel.dev
server {
    listen              80;
    listen              443 ssl;
    server_name         www.beispiel.dev;
    ssl_certificate     www.beispiel.dev.crt;
    ssl_certificate_key www.beispiel.dev.key;
    ...
}

With this configuration, Nginx can serve two HTTPS servers for different domains on the same instance.

© Ilyas Yambay, 2014-2025 | Kiss theme for Hugo