How to allow both www and no www domain and redirect to HTTPS?

After my previous post about `server_name`, I tried to do the following in order to add `www` to my server.

Before that redirection to HTTPS worked, but without `www:`

server {
    listen 80;
    server_name mysite.local;
    return 301 https://$host$request_uri;
}

server {
    listen 80;
    server_name www.mysite.local;
    return 301 https://$host$request_uri;
}

  server {   
    listen 443 ssl;
    server_name mysite.local www.mysite.local;     
    ssl_certificate /etc/ssl/mysite.local.crt;
    ssl_certificate_key /etc/ssl/mysite.local.key;

     location / {      
     proxy_pass      http://mysite.local:3000;
    }
  }

location / {            proxy\_pass      [http://mysite.local:3000](http://mysite.local:3000);     }   }

Or, I also need to add `www.mysite.local` to the `hosts` file in Windows?

1 thought on “How to allow both www and no www domain and redirect to HTTPS?”

Leave a Comment