On the port 8080
it was woking without SSL, in plain text. For adding SSL, it is not enough to just change listen 8080
into listen 443 ssl
. You need to also at least add the lines which specify certificate chain and the server private key:
listen [::]:443 ssl;
listen 443 ssl;
ssl_certificate /path/to/fullchain.pem;
ssl_certificate_key /path/to/privkey.pem;
Full chain is a simple concatenation of all certificates in the PEM form (which is text files with Base64-encoded data inside), the first certificate is your server's corresponding to the private key, then its immediate issuer CA, and so on, up to but not including the root CA.
If there are several names in the certificate (modern certificates always use subjectAlternativeNames
which permits to specify more than a single domain name), it's up to you to specify them in the server_name
option. You may only specify server names which are exist in the SAN field of the certificate, but you aren't required to use all of them. (If you specify anything other than that exists in the SAN field, your client will show an SSL certificate error that it doesn't belong to a domain when they access your server by that name.) In your case, a certificate must be valid at least for both domain.co.uk
and www.domain.co.uk
.
See Nginx HTTPS manual for details. If you use certbot
(an ACME client) with nginx install plugin to obtain a certificate, it will configure everything automatically. If you are obtaining certificates "by hand", you have to add these configuratuion options by hand too.