Redirect WWW to NON-WWW - Ghost 1 Click Install

Posted November 12, 2017 9.5k views
DigitalOceanGhostLet's EncryptUbuntu 16.04

So have followed this guide:

All works fine apart from when I try and visit the site with www in the URL.

All the browser says is “Safari cannot open the page because it could not establish a secure connection to the server”

What else do I need to do to redirect WWW to NON-WWW?

I have created an A Record for the WWW in the Domains section of the droplet.

I have also tried editing and adding the www url to the server_name entry and getting the same error.

Please help :(

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
4 answers

It sounds like your certificate does not include the www version of the domain, so your browser is rejecting the connection before the server gets a chance to issue a redirect.

If you’re using letsencrpyt, leave your non-www domain as server name, add the www domain under ServerAlias, then rerun letsencrypt and check off both domains, so it will create a certificate with both.

Hey I have the same issue. I am new to ubuntu, terminal etc. I’m sorry how do i edit the config file to add www that the ghost script created when it configured letsEncrypt? I dont see it in the directory, it says its in var folder, but i dont see that. Creating ssl config file at /var/www/ghost/system/files/

  • I followed these instructions, and although its still not working, I think I am close

    you need to add www version URL on ghost conf file

    Open sudo nano /var/www/ghost/system/files/ (Open it via Terminal/putty or FTP)

    Find this line server_name; Replace it with server_name;

    If you Install the SSL for your ghost blog you need update URL on SSL conf file too

    sudo nano /var/www/ghost/system/files/

    ghost Nginx conf File Location /var/www/ghost/system/files

    PS: Replace with your Ghost blog URL

    After all set up restart ghost and Nginx

    ghost restart
    sudo service nginx restart

    That’s all done :)

  • I found these instructions on Ghost documentation and it worked. Seems a bit more clunky with more files but it uses their script to easily configure the letsEncrypt for the new domain and then redirect it.

    SSL for additional domains
    You may wish to have multiple domains that redirect to your blog, e.g. to have an extra TLD or to support www. domains. Ghost itself can only ever have one domain pointed at it. This is intentional for SEO purposes, however you can always redirect extra domains to your Ghost install using nginx.

    If you want to redirect an HTTPS domain, you must have a certificate for it. This is where letsencrypt comes in particularly handy, because who wants to pay for SSL for a redirect?!

    If you want to use Ghost-CLI to generate an extra SSL setup, you can do this using a little trick, first run ghost config to change the domain. This will not restart Ghost, so the change won’t be reflected.

    ghost config url

    Next, get Ghost-CLI to generate an SSL setup for you:

    ghost setup nginx ssl

    You’ve now got two domains setup with SSL. Next, change your Ghost config back before you forget.

    ghost config url

    Finally, you’ll need to edit the nginx config files for your second domain to redirect to your canonical domain. Edit both /system/files/ and /system/files/, making two changes:

    remove the first location block (leave the .well-known location block - this is used for renewing certificates.

    for the redirect, you’ll need to add the following as the last line of the final block:

    return 301$request_uri;

    Once you have made those changes run sudo nginx -t to get nginx to verify your config, and sudo nginx -s reload to reload nginx and pick up your new configuration.

Worked like a charm!
Just make sure you have to cd to ghost directory (/var/www/ghost) to be able to run cli commands, also you cannot run this as root., puede ser

eso es lo único que me hace equivocar, alguien me puede ayudar por favor