I haven't really wrapped my head around how to create (working) certificates using certbot for nginx.
My sites-enables now look like this:
First, a block for the www domain with SSL. All the SSL stuff is created by certbot.
server {
root …
index …
server_name www.doman.com
listen 443 ssl;
ssl_certificate …
ssl_certificate_key …
include …
ssl_dhparam …
}
After this, a redirect from port 80 to port 443 for both www and non-www. The first part – the if statement – is created by certbot and not me.
server {
if ($host = www.example.com {
return 301 https://$host$request_uri;
}
listen *:80;
server_name domain.com www.example.com;
return 301 https://www.example.com$request_uri;
}
And finally, a block for 443 without www. I want this to redirect to www.
server {
listen 443;
server_name www.domain.com
return 301 https://www.example.com$request_uri;
}
This plays out well for the domain with www. However, without www, I get "this site cannot be reached". Even when I try it with http and and not https.
Where am I fucking this up? My guess is that the third block, that used 443 for non-www, needs SSL certificates as well. But I use certbots automatic creation, and it doesn't add any.