Certbot SSL - Wildcard certificate not covering all scenarios

Viewed 13

I have a ec2 instance running nginx. I have just added a wildcard certificate *.mywebsite.com

Most variations work, but if I type mywebsite.com directly into the browser, it redirects to https://mywebsite.com and show certificate not valid. I am wondering how to fix this?

this is my .conf file:


server {
    listen       443 ssl;
    root         /var/www/html;
    index        index.php;
    server_name  www.mywebsite.com mywebsite.com www.mywebsite.co.uk mywebsite.co.uk;
    client_max_body_size 100m;

    location / {
        #try_files $uri $uri/ =404;
        if ($request_uri ~ ^/(.*)\.html$) {  return 302 /$1;  }
        try_files $uri $uri/ $uri.html $uri.php?$args;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
    }


    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }




    ssl_certificate /etc/letsencrypt/live/mywebsite.com-0001/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mywebsite.com-0001/privkey.pem; # managed by Certbot
    
    }
    
    
server {
    if ($host = mywebsite.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = www.mywebsite.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen      80;   #listen for all the HTTP requests
    server_name mywebsite.com www.mywebsite.com;
    return      301         https://www.mywebsite.com$request_uri;
}  
0 Answers
Related