更改域名或重命名您的Discourse

:bookmark: This guide explains how-to change the domain name of your Discourse site, and includes information about setting up DNS changes, editing configuration files, updating site settings, and correcting social logins and post content to reflect your new domain name.

:warning: This guide is for self-hosted Discourse instances that were installed using our installation guide on GitHub. If you are hosted by Discourse, please see Configure your domain name for hosted Discourse for specific instructions.

You may eventually want to change the domain name of your Discourse instance, from say

=BEFORE==AFTER=

Let’s get started.

Setting the DNS TTL low in advance

First, change the Time-To-Live (TTL) setting for your DNS to a low value like 60 minutes. This should be done days ahead of the actual domain change to ensure the change can propagate quickly across the internet.

Remove old domain name from any site settings

Visit /admin/site_settings in your Discourse admin interface, and search for any settings containing the old domain name. Update these settings to the new domain name.

Changing DNS Records

Update your DNS settings to disable the old domain and point the new domain to the IP address of your Discourse server.

Editing the site name in app.yml

You can edit the app.yml file manually to input the new domain information.

Here’s how to edit it manually:

cd /var/discourse
nano containers/app.yml

Locate the following line and replace it:

DISCOURSE_HOSTNAME: 'your.newdomain.com'

If using a Content Delivery Network (CDN), temporarily disable it by commenting out the respective line in app.yml. Rebuild your Discourse site with:

./launcher rebuild app

:information_source: Alternatively, you can run ./discourse-setup again and input the new domain information instead of editing app.yml.

Check that your site is operational under the new domain.

Fixing social logins

:exclamation: Depending on how you logged in, you may need to do this first or you won’t be able to log in once the name is changed.

If you use social logins, update the credentials on the platforms (Twitter, Facebook, Google, Yahoo, GitHub) to reflect the new domain. Look for guides on the Discourse how-to category.

Remapping domain names in posts

All the existing posts will still refer to the old domain.

You’ll need to change old domain references in your posts to the new domain:

./launcher enter app

then

discourse remap =BEFORE= =AFTER=

Alternatively, use Rake if discourse binary is unavailable, you can use the rake version:

bundle exec rake posts:remap["=BEFORE=", "=AFTER="]

Finalize with:

rake posts:rebake

This ensures that the domain name remaps in existing posts, and content is regenerated as necessary.

:information_source: If you have a CDN, remember to reactivate it post-domain change.

wondering how we created that form?

Last edited by @SaraDev 2024-12-13T00:50:25Z

Check documentPerform check on document:
191 个赞

真的没有理由进行 rebake 吗?
remap 已经负责将旧 URL 映射到新 URL 了。

4 个赞

@SaraDev 感谢您保持整洁。您能否看一下:

也许我遗漏了什么,但是……如果您使用 ./discourse-setup 方法,您需要在运行 ./discourse-setup 之前为新域名设置 IP,以防止可怕的域名检查失败,哎呀。

使用 talk.foo.comtalk.bar.com 约定

您的 Discourse 的主机名? [talk.foo.com]: talk.bar.com

正在检查您的域名 . . .
警告:无法通过主机名访问计算机的 443 端口: talk.bar.com
警告:连接到 http://talk.bar.com (端口 80) 也失败。

2 个赞

您好 @philh

感谢您提出这一点:

这是正确的,如果您运行 ./discourse-setup 并输入新的域信息而不是编辑 app.yml,您将需要首先为您的新域设置 DNS 记录。

此信息已在指南中更新,以反映此情况下更新域的正确顺序。 :slightly_smiling_face:

1 个赞

谢谢 Sara!

顺便说一句:我非常确定在运行 ./launcher rebuild app 时会有一个域检查 :wink: 这表明无论如何都应该先更新 DNS:直接编辑 app.yml 或运行 ./discourse-setup

再次感谢您为保持一切整洁所做的努力。最新的说明确实能帮助那些新来的人。 :slight_smile:

2 个赞

我想这样做,但我使用的是 Digital Ocean,而且我不是专家。我需要在那儿更改任何内容吗?

例如,我看到这个:

但我认为这只是我给它起的名字,并不是一个真正的设置?

所以,只要我遵循此页面上的说明,我就不必在 Digital Ocean 中进行任何更改(也许除了将此名称更新为新域名,以避免混淆?)

要使您的新网站正常运行,您需要更新域名提供商处的 DNS 设置。


示例:

如果您的旧网站是:

forum.example.com → 1.1.1.1

那么您应该将其更改为:

forum.newname.com → 1.1.1.1


您是更改子域名还是完整域名?

在上面的示例中:

  • 域名example.com
  • 子域名forum

根据您是仅更改子域名还是更改完整域名,请确保相应地更新您的 DNS 记录。



:label: 您是更改子域名还是完整域名?

在上面的示例中:

  • 域名example.com
  • 子域名forum

根据您是仅更改子域名还是更改完整域名,请确保相应地更新您的 DNS 记录。


:globe_with_meridians: DNS 配置示例

:blue_circle: Cloudflare

  1. 登录您的 Cloudflare 控制面板
  2. 选择您的域名(例如 example.com)。
  3. 转到 DNS 选项卡。
  4. 找到 forum 的现有 ACNAME 记录。
  5. 编辑它:
    • 名称forum
    • 内容1.1.1.1(或您的服务器 IP)
  6. 点击 保存

:yellow_circle: GoDaddy

  1. 登录您的 GoDaddy 账户
  2. 点击 Domains,然后选择您的域名。
  3. Additional Settings 下,点击 Manage DNS
  4. 向下滚动到 Records 部分。
  5. 找到 forumA 记录或 CNAME,然后点击 Edit 图标。
  6. 更新以下内容:
    • Hostforum
    • Points to1.1.1.1
  7. 点击 Save

:orange_circle: Namecheap

  1. 登录您的 Namecheap 账户
  2. 转到 Domain List > 点击您域名旁边的 Manage
  3. 打开 Advanced DNS 选项卡。
  4. Host Records 下,查找 forum 条目。
  5. 点击 Edit,然后更新:
    • Hostforum
    • Value1.1.1.1
  6. 点击绿色的 checkmark 保存更改。

DNS 更改可能需要几分钟到 48 小时才能完全传播,具体取决于您的提供商和 TTL 设置。

:three_o_clock: 注意:更改 DNS 的步骤是使用 AI 生成的,它们可能有所不同或包含错误。

1 个赞

我的问题实际上只与 Digital Ocean 有关,而不是 DNS,我可以在 Cloudflare 中轻松更改。不过,我发现没有必要在 Digital Ocean 中进行任何更改。

无论如何,谢谢您的回复!

1 个赞