How to configure SNI in nginx?

1.1k Views Asked by At

I wish to serve two or more of my domain names from a single instance of nginx running on a raspberry pi, however something is not working alright.

Nginx was compiled with SNI support enabled:

> nginx -VC
nginx version: nginx/1.18.0
built with OpenSSL 1.1.1n  15 Mar 2022
TLS SNI support enabled

However I suspect that SNI is not in effect. I am trying to access my domains from multiple modern browsers guaranteed to have SNI support (firefoxes, chromes, opera and more).

My configurations are as follows: /etc/nginx/sites_enabled/domain1.conf contains the following:

server {
    listen 443 ssl;
    server_name domain1.com www.domain1.com;
    root /var/www/domain1.com/html;
    index index.html index.htm;
    ssl_certificate /var/www/domain1.com/ssl/cert.pub;
    ssl_certificate_key /var/www/domain1.com/ssl/cert.key;
    location / { try_files $uri $uri/ $uri.html =404; }
}

server {
    listen 80;
    server_name domain1.com www.domain1.com;
    return 301 https://$server_name$request_uri;
}

whereas /etc/nginx/sites_enabled/domain2.conf containsthe following:

server {
    listen 443 ssl;
    server_name domain2.net www.domain2.net;
    root /var/www/domain2.net/html;
    index index.html;
    ssl_certificate /var/www/domain2.net/ssl/cert.pub;
    ssl_certificate_key /var/www/domain2.net/ssl/cert.key;
    location / { try_files $uri $uri/ $uri.html =404; }
}

server {
    listen 80;
    server_name domain2.net www.domain2.net;
    return 301 https://$server_name$request_uri;
}

The HTTP to HTTPS redirecting works as expected i.e. in a browsers http://domain1.com correctly redirects me to https://domain1.com, however only one of the domains are actually accessible (namely domain2.net).

What could be the cause of my problem? Do I have to manually enable SNI somehow?

Note that when I set up both domains only through HTTP they both worked as expected.

0

There are 0 best solutions below