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


My ssl cert is setup correctly for my domain at However navigating to 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.


server {
    return 301$request_uri;

server {
    listen 443 ssl;
    return 301$request_uri;
server {
    # SSL configuration from Let's Encrypt
    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;
    include snippets/;
    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:

I ran this command: curl -I

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

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:

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

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

1 Like

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

1 Like

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