# 无需重建应用即可添加 Discourse 站点及 multisite.yml 问题

**URL:** <https://meta.discourse.org/t/adding-discourse-sites-without-rebuilding-the-app-and-multisite-yml-question/403367>\
**Category:** Self-hosting\
**Tags:** multisite\
**Created:** [2026年五月19日 22:17 UTC](https://meta.discourse.org/t/adding-discourse-sites-without-rebuilding-the-app-and-multisite-yml-question/403367 "2026-05-19T22:17:09Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![ScrapBlox](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/scrapblox/32/554981_2.png) [@ScrapBlox](https://meta.discourse.org/u/ScrapBlox)\
**Post date:** [2026年五月19日 22:17 UTC](https://meta.discourse.org/t/adding-discourse-sites-without-rebuilding-the-app-and-multisite-yml-question/403367/1 "2026-05-19T22:17:09Z")

</div>

我开始折腾 Discourse 的多站点实例，想知道除了通过在 app.yml 中定义站点钩子外，是否有一种方法可以将此配置为外部文件（例如 multisite.yml，但放在主机 VPS 上而不是 Docker 容器内，至少可以从主机进行配置），或者是否可以通过一个 shell 脚本在数据库表中定义 Discourse 论坛。

我还想知道，是否有命令行或其他方法可以在不重建整个应用的情况下添加新站点？

```yaml
hooks:
  after_postgres:
     # 这里需要为每个站点数据库进行设置，而不是 b_discourse
     - exec: sudo -u postgres createdb b_discourse || exit 0
     - exec:
          stdin: |
            grant all privileges on database b_discourse to discourse;
          cmd: sudo -u postgres psql b_discourse
          raise_on_fail: false

     - exec: /bin/bash -c 'sudo -u postgres psql b_discourse <<< "alter schema public owner to discourse;"'
     - exec: /bin/bash -c 'sudo -u postgres psql b_discourse <<< "create extension if not exists hstore;"'
     - exec: /bin/bash -c 'sudo -u postgres psql b_discourse <<< "create extension if not exists pg_trgm;"'

  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - mkdir -p plugins
          - git clone https://github.com/discourse/docker_manager.git
  before_bundle_exec:
    - file:
        path: $home/config/multisite.yml
        contents: |
         secondsite:
           adapter: postgresql
           database: b_discourse
           pool: 25
           timeout: 5000
           host_names:
             - sub.domain.tld

  after_bundle_exec:
    - exec: cd /var/www/discourse && sudo -H -E -u discourse bundle exec rake multisite:migrate

```

Discourse 多站点对我来说是新的，但我已经设置过 MediaWiki 多站点并且对此很熟悉。

---

_[View the full topic](https://meta.discourse.org/t/adding-discourse-sites-without-rebuilding-the-app-and-multisite-yml-question/403367)._
