This article is translated from the original English: Change the domain name or rename your Discourse
If you installed a Discourse instance by following the instructions on the Installation Guide on GitHub and wish to change the domain name of your instance, please refer to this guide. If you are using Discourse’s official hosting service, please refer to the detailed content on the Configure your domain name for hosted Discourse page.
Let’s assume you want to change your Discourse instance’s domain name from talk.foo.com to talk.bar.com.
Let’s begin the process.
Set TTL to Low in Advanced DNS Settings
You want everyone to know your domain name has been changed, so you can set the TTL (Time To Live) in your domain’s DNS to a low value, for example, 60 minutes.
The main purpose of this setting is to allow your DNS changes to take effect more quickly. DNS changes on the internet take time due to caching.
Remove All Old Domain Configurations from the Site
Visit /admin/site_settings and search for all configurations related to the old domain name.
If your search finds any configurations related to the old domain name, make sure to modify them as shown above.
Edit Discourse Configuration in app.yml File
Optionally, you can rerun the
./discourse-setupcommand and update the new domain name in theapp.ymlconfiguration file by following the prompts.
Edit the hostname content in the app.yml file.
## The hostname in your Discourse instance will be changed to the following
DISCOURSE_HOSTNAME: 'talk.bar.com'
(Also, if you are using a CDN, you can comment out the CDN configuration in app.yml. You can uncomment it after completing the modifications.)
After completing the above configurations, you need to rebuild Discourse:
./launcher rebuild app
After you complete this rebuild, your site will only be accessible via the new domain name.
Modify Your DNS Configuration
- Delete the DNS records for the old domain name.
- Modify the DNS records for the new domain name, pointing them to your Discourse service address.
After completing these configurations, you should be able to access your Discourse site via the newly modified domain name without any issues.
You can also modify your DNS configuration while rebuilding the site.
Verify that all functions are accessible. When verifying functions, we want to first ensure that we can log in to our Discourse system normally. This is what the following topic will address…
Modify Third-Party Login
Depending on how you log in, you need to make changes immediately, otherwise you will not be able to log in via third-party services after changing the domain name.
You will also need to modify your Twitter, Facebook, Google, Yahoo, and GitHub social media login configurations to ensure the callback URL matches your new address.
Please refer to the official documentation for configuration and modification.
Replace All References to the Old Site in Topics with the New Site’s Domain Name
Currently, all links to the site theme in topics and posts still use the old domain name. We need to change this so that links in posts point to the new domain name. Let’s proceed:
./launcher enter app
Then enter and execute the following command:
discourse remap =BEFORE= =AFTER=
After following the prompts, execute the following command:
rake posts:rebake
The remaps in the topics will now replace the old domain name with the new domain name, and we will regenerate all topics to avoid any omissions.
At this point, all domain name change configurations are complete!
(If you commented out the CDN configuration at the beginning, don’t forget to uncomment it.)
Want to know how the input dialog in topics is created?
Please refer to the original article How to Change Discourse Domain Name - Discourse - OSSEZ for more information.
Thanks to the official support.
