Make the www or apex name work over HTTPS on nginx
Why it matters
The other spelling of the domain resolves in DNS but fails over HTTPS, so visitors who type it get an error. Either serve it with a valid certificate and redirect it to the main host, or remove its DNS record.
The fix
- Add the other name to the certificate (sudo certbot --nginx --expand -d example.com -d www.example.com).
- Add a port 443 server for it that returns 301 https://example.com$request_uri, run sudo nginx -t and reload.
The examples use example.com. Replace it with your own domain.
Related
- Reported by the HTTP to HTTPS redirect check
- Serve the site over HTTPS
- Stop redirecting HTTPS to HTTP
- Redirect HTTP to HTTPS
- Fix the broken HTTPS redirect chain
- Shorten the redirect chain
- Fix the HTTP redirect chain
- Redirect HTTP straight to HTTPS
- Answer HTTP with a redirect to HTTPS
- Redirect www and apex to one host
Scan your domain to see whether this applies to you.