Change your Ghost site to a new domain

Moving your Ghost site to a new URL shouldn't be hard.

So, you've launched your Ghost site in a specific domain, like www.example.net but since then you found out that it's not the best domain for your site or you got a much better domain name later, like www.example.com, and then you want to move? You're in luck, this guide will teach you how.

I recently migrated to a new domain and this guide is the result of that process. This is similar to redirecting non-www to www URLs on Ghost, so if you've done that already, this is going to be a breeze for you.

Keep in mind that doing this is gonna give you a temporary setback from whatever SEO you've built for your site, but we're going to make everything possible to not destroy it.

Let's jump into it!

Prerequisites


  • This guide is written for people that have a Ghost instance running on a VPS (self-hosting). This can be from any provider, but for this guide, I'm using the Ghost Hosting 1-Click App from Digital Ocean. You can create a DigitalOcean account using my referral link and get $100 USD for free.
  • You have DNS access to your current domain, like example.net. And DNS access to your new domain, like example.com, which is where you want to move.
  • You know how to login to your VPS using ssh or, if you are using DigitalOcean, you can use the Droplet Console.
  • Backup everything. If something went wrong, you can just rollback and go unaffected from any change you make from now on. You can manually backup all your content using the Ghost migration guide and create an on-demand disk image using snapshots on DigitalOcean. It is human nature to err, and believe me, I've err many times tinkering this site.

Redirecting your site to the new domain


Read through these steps, before you follow them closely, step by step. Don’t miss a single one of them (except, maybe the last one), and you’ll be perfectly fine β€” both for now and in the future.

Step 1: Assign your current VPS IP to your new domain

Let's say that the current assigned IP address of your site is 178.128.137.126. You should have two A records pointing to your current domain example.net:

New Domain DNS Configuration (example.net)
Record Type Host Value
A @ 178.128.137.126
A www 178.128.137.126

You should assign the same IP address to your new domain, two A records pointing to your new domain example.com:

New Domain DNS Configuration (example.com)
Record Type Host Value
A @ 178.128.137.126
A www 178.128.137.126

Note that domain propagation can take anywhere from 5 mins to 48 hours (or more, depends on the TTL configuration of your domain). Be sure that it propagates before proceeding with the following steps.

Step 2: Set up an SSL certificate for your new domain

SSL certificates are what enable websites to move from HTTP to HTTPS, which is more secure. Ghost and Let's Encrypt made it easy to set it up, let's get right into it.

Login to your VPS using ssh (or login using the Droplet Console).

ssh [email protected]

Log as the user that manages your Ghost instance. If you are using the DigitalOcean 1-Click App, it's gonna be ghost-mgr.

sudo -i -u ghost-mgr

Locate your Ghost instance, which is typically located in /var/www/ghost. Change directory to that location.

cd /var/www/ghost

Configure your new domain www.example.com (or whichever it is) on Ghost.

ghost config url https://www.example.com

Then setup the SSL certificate for the new domain.

ghost setup nginx ssl

Remember to setup the SSL certificate for your root (naked) domain too, i.e. example.com (without the www).

ghost config url https://example.com;
ghost setup nginx ssl

Whether you want to use the www or non-www domain is up to you. If you want to keep it as your root domain (non-www), leave it as is, otherwise, remember to config your ghost domain back to the www domain using ghost config url https://www.example.com.

Learn more about redirecting non-www to www URLs on Ghost and vice-versa here.

Step 3: Set up 301 redirects for your website

A 301 redirect tells Google that your website is permanently moving to a new domain. While Google supports different types of redirects, 301s are the preferred method.

Make sure to apply the 301 redirects on a page by page basis. For this guide, I'm gonna redirect everything from www.example.net to www.example.com.

Please, change the domain names for whichever case you're working on, the process should be the same. Let's do it!

Locate your virtual host configuration file, which is typically located in /etc/nginx/sites-available. Change directory to that location.

cd /etc/nginx/sites-available

Right here (following the example domains that we're using for this guide), if you run ls, you should see a list similar to this:

default
example.com.conf
example.com-ssl.conf
example.net.conf
example.net-ssl.conf
www.example.com.conf
www.example.com-ssl.conf
www.example.net.conf
www.example.net-ssl.conf

List after running ls.

Let's get started on the redirects.

www.example.net redirect to www.example.com

Edit the two Nginx files for www.example.net using a text editor like vim or nano. These files would be www.example.net.conf and www.example.net-ssl.conf.

Within the server block add the following: return 301 https://www.example.com$request_uri; line. Do the same in both files:

server {
    listen 80;
    listen [::]:80;

    server_name www.example.net;

    # THIS IS THE NEW LINE:
    return 301 https://www.example.com$request_uri;
    ##############################################

    root /var/www/ghost/system/nginx-root; 
    # Used for acme.sh SSL verification (nttps://acme.sh)

    ...
}

www.example.net.conf file.

server {
    listen 443 ssl http2;
    listen [::]:443 http2;

    server_name www.example.net;

    # THIS IS THE NEW LINE:
    return 301 https://www.example.com$request_uri;
    ##############################################

    root /var/www/ghost/system/nginx-root; 
    # Used for acme.sh SSL verification (nttps://acme.sh)

    ...
}

www.example.net-ssl.conf file.

Let's not forget about redirecting our root domains to the new www domain.

example.net redirect to www.example.com

Edit the two Nginx files for example.net using a text editor like vim or nano. These files would be example.net.conf and example.net-ssl.conf.

Within the server block add the following: return 301 https://www.example.com$request_uri; line. Do the same in both files:

server {
    listen 80;
    listen [::]:80;

    server_name example.net;

    # THIS IS THE NEW LINE:
    return 301 https://www.example.com$request_uri;
    ##############################################

    root /var/www/ghost/system/nginx-root; 
    # Used for acme.sh SSL verification (nttps://acme.sh)

    ...
}

example.net.conf file.

server {
    listen 443 ssl http2;
    listen [::]:443 http2;

    server_name example.net;

    # THIS IS THE NEW LINE:
    return 301 https://www.example.com$request_uri;
    ##############################################

    root /var/www/ghost/system/nginx-root; 
    # Used for acme.sh SSL verification (nttps://acme.sh)

    ...
}

example.net-ssl.conf file.

example.com redirect to www.example.com

Edit the two Nginx files for example.com using a text editor like vim or nano. These files would be example.com.conf and example.com-ssl.conf.

Within the server block add the following: return 301 https://www.example.com$request_uri; line. Do the same in both files:

server {
    listen 80;
    listen [::]:80;

    server_name example.com;

    # THIS IS THE NEW LINE:
    return 301 https://www.example.com$request_uri;
    ##############################################

    root /var/www/ghost/system/nginx-root; 
    # Used for acme.sh SSL verification (nttps://acme.sh)

    ...
}

example.com.conf file.

server {
    listen 443 ssl http2;
    listen [::]:443 http2;

    server_name example.com;

    # THIS IS THE NEW LINE:
    return 301 https://www.example.com$request_uri;
    ##############################################

    root /var/www/ghost/system/nginx-root; 
    # Used for acme.sh SSL verification (nttps://acme.sh)

    ...
}

example.com-ssl.conf file.

This was a little repetitive, not gonna lie.

But there we go, we're done editing files! Restart Nginx.

sudo service nginx restart

And restart Ghost.

cd /var/www/ghost;
ghost restart

Now your website and every page on it should be redirecting from www.example.net to www.example.com!

Step 4: Google Search Console

We're basically done with the guide, but a recommendation that I'd give is telling Google that you recently changed domains so that your site's SEO doesn't get hurt a lot.

If you registered your current domain on Google's Search Console (if you didn't, then skip this whole step 4) you're gonna have to tell Google that you're changing domains.

For that, please follow the excellent Change of Address Tool guide. The Step 1: Pre-work is basically done for us, so you can skip straight to Step 2 in Google's guide.

Step 2: Use the Change of Address tool

After performing the pre-work, if you fulfill the requirements below, you can use the Change of Address tool to forward your old site signals to your new site.

Requirements:
- You must be a verified owner of both the old and new properties in Search Console. You must use the same Google account to manage both properties.

- The Change of Address tool can be used only on properties at the domain level: that is, you can move example.com, m.example.com, or http://example.com. You cannot move properties at the path level, such as http://example.com/petstore/

- The tool does not move any subdomains below the specified domain (including www). So if you specify example.com in the tool, it will not move www.example.com or m.example.com. However, all paths under the domain are affected (example.com/any/path/here).

- The tool moves all protocols of your source property. So if you specify http://example.com, it also moves https://example.com

Use the Change of Address tool:

1. Perform Step 1: Pre-work.
2. Ensure that you fulfill all the requirements listed above.
3. Open the Change of Address tool in a property that is at the domain level (that is, it has no path segments--example.com, not example.com/petstore).
4. Follow the instructions provided in thetool. The tool runs a few pre-move checks before telling Google about the move. If you fail any critical pre-move checks, you must fix the issue before you can continue. If you fail non-critical pre-move checks, you will see a warning with recommendations, but your request can continue.
5. If critical pre-checks pass, all sites being migrated from or to will display a notification in Search Console that the move is in progress. You will see these notifications for 180 days.
6. Monitor your traffic as indicated in Move a site with URL changes.
7. Maintain the redirects for at least 180 days--longer if you still see any traffic to them from Google Search. Remove your old pages, but we recommend continuing to pay for the old domain for at least a year to prevent others from buying and using your abandoned domain for malicious purposes. After the 180 day period, Google does not recognize any relationship between the old and new sites, and treats the old site as an unrelated site, if still present and crawlable.

Step 5: Reconfigure config.production.json

You may need to reconfigure the URL from the config.production.json file. For that, do the following on your server.

  1. Log as the user that manages your Ghost instance. If your are using the DigitalOcean 1-Click App, it's gonna be ghost-mgr. Run the following command on your VPS console:
sudo -i -u ghost-mgr

2. Locate your Ghost instance, which is typically located in /var/www/ghost. Change directory to that location:

cd /var/www/ghost

3. Edit and change the URL from the config.production.json file:

# Start of the file.

{
  "url": "https://www.example.net",
  "server": {
    "port": 2368,
    "host": "127.0.0.1"
  },
  
 ...

Original URL configuration.

# Start of the file.

{
  "url": "https://www.example.com",
  "server": {
    "port": 2368,
    "host": "127.0.0.1"
  },
  
 ...

New URL configuration.

Now you are all set. Enjoy and tell all your readers about your new domain!