mardi 27 novembre 2018

Nginx redirect everything to www https

I want to redirect everything to https://www

This is my config block where I tried redirecting non www to https but does not work.

server {
    listen 80;
    server_name example.com
    return 301 https://www.$server_name$request_uri;
}
server {
    listen 80;
    server_name www.example.com;

    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;

    location /auth {
        ...
    }

    location / {
       ...
    }

    ssl_certificate /root/certs/fullchain.pem;
    ssl_certificate_key /root/certs/privkey.pem;

}

http://example.com gives 404 error

https://example.com does not redirect to https://www

http://www.example.com redirects to https://www

https://www.example works as is




Aucun commentaire:

Enregistrer un commentaire