I configured NGINX to redirect all HTTP traffic to HTTPS like this:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name domain.com www.domain.com;
    return 301 https://$host$request_uri;

(Not literally domain.com, but my actual domain name)

The redirects are working correctly for domain.com, but when I try accessing www.domain.com, I still get the HTTP version.

Any idea why that could be?


Nevermind, had the Let's Encrypt certbot adding another listen 80 directive to my HTTPS server block.

Fixed by leting Let's Encrypt manage HTTP -> HTTPS rules (pass "--redirect" to cerbot command).

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.