# Change subdomain of ghost blog

**URL:** <https://forum.ghost.org/t/change-subdomain-of-ghost-blog/25985>\
**Category:** Installation\
**Created:** [September 30, 2021, 6:14am UTC](https://forum.ghost.org/t/change-subdomain-of-ghost-blog/25985 "2021-09-30T06:14:15Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![JLL](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/jll/32/10049_2.png) [@JLL](https://forum.ghost.org/u/JLL)\
**Post date:** [September 30, 2021, 6:14am UTC](https://forum.ghost.org/t/change-subdomain-of-ghost-blog/25985/1 "2021-09-30T06:14:15Z")

</div>

I am hosting a ghost blog on digitalocean. It is running fine. I would like to change the URL to use a new subdomain. The main domain remains the same.

Suppose the old URL is `old-subdomain.maindomain.com`. I want to change the URL to a new subdomain `new-subdomain.maindomain.com`.

How do I go about doing this? Thank you.

---

<div class="post-metadata">

**Author:** ![EmpiricalEE](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/empiricalee/32/15201_2.png) [@EmpiricalEE](https://forum.ghost.org/u/EmpiricalEE)\
**Post date:** [September 30, 2021, 8:17am UTC](https://forum.ghost.org/t/change-subdomain-of-ghost-blog/25985/2 "2021-09-30T08:17:18Z")

</div>

I’m looking forward to seeing the responses to this. It should be as simple as:

1. adding or changing the `server_name` setting in your site’s `nginx` config file in `/etc/nginx/sites-enabled/`. Eg:

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

    server_name new-subdomain.maindomain.com;
    ...

```

1. Changing the `url` setting in your site’s config file. Eg. using the cli: `ghost config url new-subdomain.maindomain.com`.

2. Making sure the DNS record for the new sub-domain points at the same IP address. If you already have a wildcard (`*`) A record for your domain that points to the right IP address, there will be nothing to do.

But 10 years since the “SSL By Default” campaign started, and I still find it the most infuriating part of server admin. So I don’t know how you should change your subdomain without invalidating your certificate. Even nginx seems [short on ideas](http://nginx.org/en/docs/http/configuring_https_servers.html).

---

<div class="post-metadata">

**Author:** ![prokopton](https://avatars.discourse-cdn.com/v4/letter/p/4da419/32.png) [@prokopton](https://forum.ghost.org/u/prokopton)\
**Post date:** [September 30, 2021, 11:29am UTC](https://forum.ghost.org/t/change-subdomain-of-ghost-blog/25985/3 "2021-09-30T11:29:51Z")

</div>

If someone already has a certificate from Let’s Encrypt DIRECTLY (one issued with Certbot), they can expand/extend the certificate to include the new subdomain:

$ sudo certbot --webroot -w /var/www/ghost certonly -d [maindomain.com](http://maindomain.com) -d [new-subdomain.maindomain.com](http://new-subdomain.maindomain.com)

OR

$ sudo certbot certonly --expand --rsa-key-size=4096 -n --webroot -w /var/www/ghost -d [new-subdomain.maindomain.com](http://new-subdomain.maindomain.com)

---

<div class="post-metadata">

**Author:** ![JLL](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/jll/32/10049_2.png) [@JLL](https://forum.ghost.org/u/JLL)\
**Post date:** [September 30, 2021, 1:48pm UTC](https://forum.ghost.org/t/change-subdomain-of-ghost-blog/25985/4 "2021-09-30T13:48:53Z")

</div>

I managed to change the subdomain. I didn’t have to do much.

What I did was;

- Add new DNS record for the new subdomain to Cloudfare.
- Run the ghost-cli command `ghost config URL https://new-subdomain.maindomain.com`

That’s about it. I do not have to get new SSL cert. I think it’s because the SSL cert was generated for the main domain which remains the same.

---

<div class="post-metadata">

**Author:** ![EmpiricalEE](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/empiricalee/32/15201_2.png) [@EmpiricalEE](https://forum.ghost.org/u/EmpiricalEE)\
**Post date:** [September 30, 2021, 11:18pm UTC](https://forum.ghost.org/t/change-subdomain-of-ghost-blog/25985/5 "2021-09-30T23:18:00Z")

</div>

> [@JLL](#):
>
> That’s about it. I do not have to get new SSL cert. I think it’s because the SSL cert was generated for the main domain which remains the same.

According to your URL, you’re not using SSL. Hence not needing a cert!

---

<div class="post-metadata">

**Author:** ![EmpiricalEE](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/empiricalee/32/15201_2.png) [@EmpiricalEE](https://forum.ghost.org/u/EmpiricalEE)\
**Post date:** [September 30, 2021, 11:28pm UTC](https://forum.ghost.org/t/change-subdomain-of-ghost-blog/25985/6 "2021-09-30T23:28:35Z")

</div>

> [@prokopton](#):
>
> If someone already has a certificate from Let’s Encrypt DIRECTLY (one issued with Certbot), they can expand/extend the certificate to include the new subdomain:
> 
> $ sudo certbot --webroot -w /var/www/ghost certonly -d [maindomain.com](http://maindomain.com) -d [new-subdomain.maindomain.com](http://new-subdomain.maindomain.com)
> 
> OR
> 
> $ sudo certbot certonly --expand --rsa-key-size=4096 -n --webroot -w /var/www/ghost -d [new-subdomain.maindomain.com](http://new-subdomain.maindomain.com)

This looks awesome, thank you! Alas, there was a bit of devil in the detail. For other’s sake, here’s how I got it to work:

- `certbot` can be installed on Ubuntu using `sudo apt install certbot`.
- As you say, you need to already have a certificate issued using `certbot`. This is **not** the case in the default Ghost install (which I think uses `/etc/letsencrypt/acme.sh` instead).
- However, you can just run the command twice - once to get a new certificate, and once to expand it!
- Note that the `-w` directory needs to be `/var/www/ghost/system/nginx-root` in order for the `.well-known/acme-challenge` stuff to work, otherwise `certbot` can’t find your existing certificate.
- The `-n` flag in the second command causes it to fail, because you need to accept the tos and provide an email address. Either remove that flag so it runs interactively, or add the `--agree-tos` and `--email <email_address>` flags.
- In fact, just using the first command will prompt you to expand the existing cert anyway.
- You need to change the `ssl_certificate` and `ssl_certificate_key` settings in your `nginx` `sites-enabled` file to point to the new certificate issued by `certbot`.
- You need to restart nginx after making a config change, or even just modifying the cert, with `sudo service nginx restart`. Note that if it fails the `systemctl` mess on Ubuntu wont tell you why - check `/var/log/syslog` instead.

And voila! It’s “easy” to add additional subdomains to your certificate.

One doubt that remains - given that Ghost uses `crontab` to periodically renew the certificate automatically, wont this now fail because it uses `acme.sh` instead of `certbot`?

---

<div class="post-metadata">

**Author:** ![JLL](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/jll/32/10049_2.png) [@JLL](https://forum.ghost.org/u/JLL)\
**Post date:** [September 30, 2021, 11:53pm UTC](https://forum.ghost.org/t/change-subdomain-of-ghost-blog/25985/7 "2021-09-30T23:53:33Z")

</div>

I made a typo. My URL starts with https, not HTTP. Thanks for pointing it out.

---

<div class="post-metadata">

**Author:** ![JLL](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/jll/32/10049_2.png) [@JLL](https://forum.ghost.org/u/JLL)\
**Post date:** [September 30, 2021, 11:55pm UTC](https://forum.ghost.org/t/change-subdomain-of-ghost-blog/25985/8 "2021-09-30T23:55:54Z")

</div>

I installed Ghost using DigitalOcean 1-click ghost droplet. Recently, I noticed that the SSL cert was automatically renewed. I didn’t have to do anything.

---

<div class="post-metadata">

**Author:** ![EmpiricalEE](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/empiricalee/32/15201_2.png) [@EmpiricalEE](https://forum.ghost.org/u/EmpiricalEE)\
**Post date:** [December 19, 2021, 11:50pm UTC](https://forum.ghost.org/t/change-subdomain-of-ghost-blog/25985/9 "2021-12-19T23:50:48Z")

</div>

Okay it’s been 2 months so I’m about to find out whether renewal still works since switching from `acme.sh` to `certbot`. The `acme.sh` cron job is still working, but I guess it’s just renewing certificates I don’t use anymore. But now I see from [this](https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-18-04#step-5-%E2%80%94-verifying-certbot-auto-renewal) that `certbot` automatically installs a renewer too (sneakily hidden from `crontab`).

Tomorrow it’ll tick over to \<30 days to expiry, so we’ll find out!

---

<div class="post-metadata">

**Author:** ![EmpiricalEE](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/empiricalee/32/15201_2.png) [@EmpiricalEE](https://forum.ghost.org/u/EmpiricalEE)\
**Post date:** [December 21, 2021, 1:41pm UTC](https://forum.ghost.org/t/change-subdomain-of-ghost-blog/25985/10 "2021-12-21T13:41:17Z")

</div>

Cert updated! I didn’t realise at first, because the web server needs to be rebooted for the new cert to take effect. The actual cert date can be verified with `sudo certbot certificates`. So if I forget to reboot every 60 to 90 days, the auto-renewal is useless. Will take note!
