Redirect www to non-www

Hey team, I’m new to Ghost - sorry for questions :slight_smile:

Seems, I just installed Ghost on

But, there is no redirect from e.g. to non-www

I followed steps here Www to non-www on Digitalocean setup and here Solved: Need help on redirecting www. to non www. - GoDaddy Community

But, still doesn’t redirect…

Hi Andrii.

You need to make some changes in nginx to make this work. There are a few different ways.

The easiest (but not the cleanest) way I’ve found is to get into the command line:

ghost config url
ghost setup nginx ssl

This creates the necessary SSL certificates and Nginx files to handle redirecting properly.

Run ghost config url to reset the domain setting.

Then you need to edit the two new Nginx files that are created (you’ll see them printed in the console) starting with (one will have -ssl in the name and one won’t).

Within the server block add a new line (do the same in both files):

return 301$request_uri;

This will direct all traffic to your www domain, to your non-www domain.

Like I said, this may not be the cleanest way to do this but it’s the easiest I’ve discovered. Alternatively you could edit the existing Nginx files and create the SSL certificates from the command line. If anyone has any feedback on this, I’d love to hear it.

1 Like

What worked for me was:

  1. Configuring only the A records following this DigitalOcean tutorial
  2. For nginx I followed the Ghost docs (similar to what dan wrote). I pasted the redirect differently according to the docs instead.
  3. Reload nginx by running systemctl reload nginx and authenticating as the ghost user.
  4. To check that it worked, use curl -I and you should get a 301 Moved Permanently response.

Step 2 in detail

The nginx configuration files can be found in /etc/nginx/sites-available.

I pasted the return 301$request_uri; line into the location block, like the documentation suggested.

So this:

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;


    location / {
        return 301$request_uri;

I went ahead to configure the http files to redirect to https as well.

1 Like