Redirect www to non www not working (ssl cert not valid)


#1

Hi,

My ssl cert is setup correctly for my domain at http://preppaired.com. However navigating to www.preppaired.com produces an ssl certifcate not valid error. I’ve tried redirecting the www subdomain to the non www one through nginx but it’s not working. I’ve tried several different configurations from various guides, here’s my current .conf file.

Nginx.conf:

server {
    server_name preppaired.com www.preppaired.com;
    return 301 https://preppaired.com$request_uri;
}

server {
    listen 443 ssl;
    server_name www.preppaired.com
    return 301 https://preppaired.com$request_uri;
}
server {
    # SSL configuration from Let's Encrypt
    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;
    include snippets/ssl-preppaired.com.conf;
    include snippets/ssl-params.conf;

        # Pass requests for / to localhost:8080:
        location / {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-NginX-Proxy true;
                proxy_pass http://localhost:8080/;
                proxy_ssl_session_reuse off;
                proxy_set_header Host $http_host;
                proxy_cache_bypass $http_upgrade;
                proxy_redirect off;
        }
}

Please fill out the fields below so we can help you better.

My domain is: preppaired.com

I ran this command: curl -I https://www.preppaired.com

It produced this output: curl: (51) SSL: certificate subject name (preppaired.com) does not match target host name ‘www.preppaired.com

My operating system is (include version): Ubuntu 16.04

My web server is (include version): Nodejs (6.5.0), Nginx (1.10.0)

My hosting provider, if applicable, is: digitalocean.com

I can login to a root shell on my machine (yes or no, or I don’t know): yes

I’m using a control panel to manage my site (no, or provide the name and version of the control panel): no


#2

You have issued the certificate for preppaired.com only it seems. Re-issue with both names and it should be OK.


#3

Thank you! This fixed it. I wasn’t sure if registering each subdomain was the correct way to do this.


#4

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.