在 CloudPanel 上安装 Discourse

:warning: This installation method is not officially endorsed. Use at your own risk.

The Discourse team only recommend installation using the official install guide

:information_source: This is an unsupported install, appropriate for those who have experience with CloudPanel, are experienced system administrators, and comfortable with docker, reverse proxies, and have successfully completed a standard installation.

Why CloudPanel

Why might you want to install a Discourse Forum on a VPS or Dedicated Server running CloudPanel?

Here are my reasons:

I prefer to use a graphical interface for server and site administration. I’ve used most of the web hosting control panels at one time or another.

In comparison to the rest, CloudPanel is very slim and minimal and uncluttered. It has every feature I need, presented very simply and intuitively. And that’s it. It has nothing I don’t need.

I develop and host and manage many Ghost blogs, Wordpress sites, Drupal sites, and other types of sites in addition to Discourse forums. I really only need one server where I can host my Discourse forums right along side my Ghost Blogs and my Wordpress and Drupal sites. (I don’t want to pay for and maintain a separate server for each instance of Discourse.)

CloudPanel includes (right out-of-the-box) built-in Nginx and a simple interface for setting up and managing Reverse Proxies which are necessary in order to run one or more instances of Discourse on the same server or with other types of websites.

The Discourse team (and the Meta forum staff here) do not provide support for alternative server environments like Cpanel or Plesk or (as in this case) CloudPanel, or others that rise up out of the command line.

So I thought I’d share my setup and my process in case there are others who might find it useful.

[If anyone tries this method, please do let me know if/how it works out for you, or if I can improve this tutorial! :heart_eyes: ]

Install Docker

In Putty (or other terminal), from the root directory, run

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu focal stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt-get install docker-ce docker-ce-cli docker-compose containerd.io

Create a Reverse Proxy Site in CloudPanel

→ We click the + Add Site button…

For my Discourse instance I am using my domain name noobish.me, so from now on wherever you see that in the rest of these instructions, replace noobish.me with your actual domain name (for example, yoursite.com)

→ We create a new “Reverse Proxy Site” in the CloudPanel for the domain where we want to host our Discourse forum (of course the DNS A record of the domain needs to be pointing to the same IP address as our CloudPanel.)

Prepare the Domain and Set up SSL

cloudflare-logo

For my site I’m using Cloudflare’s nameservers to point the domain. In Cloudflare I set the SSL to Full or Full (strict).

I also create a Cloudflare Page Rule. Visit this post to learn why.

I’m also using a free Cloudflare SSL Origin Certificate for my domain, which I “Import” into CloudPanel within the “SSL/TLS” site settings for that site (by simply pasting in both the Certificate and the Private Key I had downloaded for that domain name from my Cloudflare account.)

Install Discourse

Back in Putty (or other terminal), from the root directory (c d Enter to get back to the root) → Install the Discourse Standard Install using these commands…

git clone https://github.com/discourse/discourse_docker.git /var/discourse

Enter

cd /var/discourse

Enter

chmod 700 containers

Copy the Standalone Configuration

Now we copy the file /var/discourse/standalone.yml to /var/discourse/containers/ as app.yml before editing it according to our site settings.

cp /var/discourse/samples/standalone.yml /var/discourse/containers/app.yml

Edit the app.yml File

In addition to modifying the app.yml file according to our specific site settings, we need to change 3 more things in that file before we save it…

Under the section templates: we need to add

  - "templates/web.socketed.template.yml"

Because I’m using Cloudflare, under the section templates: I also add

  - "templates/cloudflare.template.yml"

Under the section expose: we need to comment out

  #- "80:80"   # http
  #- "443:443" # https

Under the section env: we need to add

   DISCOURSE_FORCE_HTTPS: true
For reference, you can Click Here to see the contents of my working app.yml on noobish.me where I'm using both Cloudflare and Mailgun...
## this is the all-in-one, standalone Discourse Docker container template
##
## After making changes to this file, you MUST rebuild
## /var/discourse/launcher rebuild app
##
## BE *VERY* CAREFUL WHEN EDITING!
## YAML FILES ARE SUPER SUPER SENSITIVE TO MISTAKES IN WHITESPACE OR ALIGNMENT!
## visit http://www.yamllint.com/ to validate this file as needed

templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"
  - "templates/web.socketed.template.yml"
  - "templates/cloudflare.template.yml"

params:
  db_default_text_search_config: "pg_catalog.english"

  ## Set db_shared_buffers to a max of 25% of the total memory.
  ## will be set automatically by bootstrap based on detected RAM, or you can override
  db_shared_buffers: "4096MB"

  ## can improve sorting performance, but adds memory usage per-connection
  #db_work_mem: "40MB"

  ## Which Git revision should this container use? (default: tests-passed)
  #version: tests-passed

env:
  LC_ALL: en_US.UTF-8
  LANG: en_US.UTF-8
  LANGUAGE: en_US.UTF-8
  # DISCOURSE_DEFAULT_LOCALE: en

  DISCOURSE_FORCE_HTTPS: true

  ## How many concurrent web requests are supported? Depends on memory and CPU cores.
  ## will be set automatically by bootstrap based on detected CPUs, or you can override
  UNICORN_WORKERS: 8

  ## TODO: The domain name this Discourse instance will respond to
  ## Required. Discourse will not work with a bare IP number.
  DISCOURSE_HOSTNAME: 'noobish.me'

  ## Uncomment if you want the container to be started with the same
  ## hostname (-h option) as specified above (default "$hostname-$config")
  #DOCKER_USE_HOSTNAME: true

  ## TODO: List of comma delimited emails that will be made admin and developer
  ## on initial signup example 'user1@example.com,user2@example.com'
  DISCOURSE_DEVELOPER_EMAILS: 'admin@noobish.me'

  ## TODO: The SMTP mail server used to validate new accounts and send notifications
  # SMTP ADDRESS, username, and password are required
  # WARNING the char '#' in SMTP password can cause problems!
  DISCOURSE_SMTP_ADDRESS: smtp.mailgun.org
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: postmaster@noobish.me
  DISCOURSE_SMTP_PASSWORD:  pYdRLyQW
  #DISCOURSE_SMTP_ENABLE_START_TLS: true           # (optional, default true)
  #DISCOURSE_SMTP_DOMAIN: noobish.me    # (required by some providers)
  DISCOURSE_NOTIFICATION_EMAIL: noreply@noobish.me    # (address to send notifications from)

  ## The http or https CDN address for this Discourse instance (configured to pull)
  ## see https://meta.discourse.org/t/14857 for details
  #DISCOURSE_CDN_URL: https://discourse-cdn.example.com

  ## The maxmind geolocation IP address key for IP address lookup
  ## see https://meta.discourse.org/t/-/137387/23 for details
  #DISCOURSE_MAXMIND_LICENSE_KEY: 1234567890123456

## The Docker container is stateless; all data is stored in /shared
volumes:
  - volume:
      host: /var/discourse/shared/standalone
      guest: /shared
  - volume:
      host: /var/discourse/shared/standalone/log/var-log
      guest: /var/log

## Plugins go here
## see https://meta.discourse.org/t/19157 for details
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git

## Any custom commands to run after building
run:
  - exec: echo "Beginning of custom commands"
  ## If you want to set the 'From' email address for your first registration, uncomment and change:
  ## After getting the first signup email, re-comment the line. It only needs to run once.
  #- exec: rails r "SiteSetting.notification_email='info@unconfigured.discourse.org'"
  - exec: echo "End of custom commands"

Then we save and exit the app.yml file…

CTRL-X

y

Enter

Next we set the permissions for the app.yml file…

chmod o-rwx containers/app.yml

then…

Bootstrap the App

cd /var/discourse
./launcher bootstrap app

This will take a considerable amount of time. In the end of the bootstrap process, you’ll be asked to:

./launcher start app

Edit the Vhost File

Now we go back into our CloudPanel and paste the below code into the “Vhost Editor” for our Discourse site (overwriting what is already there). Of course replace yoursite.com with your actual domain name.

server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  {{ssl_certificate_key}}
  {{ssl_certificate}}
  server_name yoursite.com;
  {{root}}

  {{nginx_access_log}}
  {{nginx_error_log}}

  if ($scheme != "https") {
    rewrite ^ https://$host$uri permanent;
  }

  location ~ /.well-known {
    auth_basic off;
    allow all;
  }

  {{settings}}

  add_header Cache-Control no-transform;

  location / {
                proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:;
                proxy_set_header Host $http_host;
                proxy_http_version 1.1;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Real-IP $remote_addr;

  }
}

Restart Nginx

Next we need to restart Nginx, which we can do by clicking a button in the Admin Area of the CloudPanel…

Congratulations!

Now, in our browser, we can go to our site’s URL and run the Discourse Setup Wizard…

Cohabitate Peacefully

Now I can self-host and manage my Discourse site right along side my Ghost, Wordpress, Drupal and other types of sites using a clean and lean management panel, with minimal need going forward to use the terminal/command line.


To Install Additional Discourse Instances…

3 个赞

您应该删除这些步骤,然后创建一个不产生此错误的 app.yml 文件。这会让人感到困惑。

(如果您要替换整个文件,为什么要复制示例?)更好的做法是说明需要从现有示例中更改什么。看起来是 socket 模板和强制 https。

这会导致您有两个 postgres 副本,消耗的内存比单个 postgres 多。虽然可行,但这并非最佳实践。

有许多因素使得这并非一个好的示例,并且将极难获得支持。我很高兴您为自己找到了解决方案,但我认为这不是一个应该引导人们走的正确方向。

3 个赞

感谢 @pfaffman

你说得对。它能完成工作,但过程太混乱了。顺序不对。我感谢你的建议,我会把它修正好。

你能解释一下为什么你这么认为吗?

因为它很复杂,而且只适合那些能够自己弄清楚的人。这很浪费,如果目标只是运行两个讨论区,在大多数情况下,两个独立的虚拟机是更便宜、更简单的解决方案。

2 个赞

再次感谢 @pfaffman——我现在已经简化了该过程,并删除了关于在同一服务器上添加第二个 Discourse 站点的部分。

1 个赞

我收到了这个消息

sudo apt update
sudo apt-get install docker-ce docker-ce-cli docker-compose containerd.io
usage: gpg [options] --dearmor [file]
curl: (23) Failed writing body

为什么?

安东尼奥,你好。欢迎。

这似乎是 Docker 的问题,而不是 Discourse 的问题。你最好搜索你的操作系统并更新 docker-ce,而不是在这里提问。

你是在尝试使用 Discourse 还是 CloudPanel?

1 个赞

我刚按照这里的指南操作。我运行了第一个命令,用于 Docker 安装,服务器响应如下:
命令是:

1 个赞

每行末尾不应有反斜杠。反斜杠会转义换行符,这意味着 shell 会将下一行视为同一行的延续。

在这种情况下,这将导致尝试将此作为单个命令运行,这就是错误来源:
sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu focal stable\"

只需删除行末尾的反斜杠即可解决此问题:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu focal stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt-get install docker-ce docker-ce-cli docker-compose containerd.io
2 个赞

谢谢,现在运行正常

2 个赞

谢谢 @Simon_Manning – 我已移除置顶帖子教程中的代码片段中的反斜杠。

2 个赞

抱歉,我现在遇到这个错误: FAILED

Pups::ExecError: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_SMTP_ADDRESS"] == "smtp.example.com"; puts "Aborting! Mail is not configured!"; exit 1; end' failed with return #<Process::Status: pid 112 exit 1>
Location of failure: /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.1.1/lib/pups/exec_command.rb:117:in `spawn'
exec failed with the params "/usr/local/bin/ruby -e 'if ENV[\"DISCOURSE_SMTP_ADDRESS\"] == \"smtp.example.com\"; puts \"Aborting! Mail is not configured!\"; exit 1; end'"
bootstrap failed with exit code 1
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.
214c73c4474ed59e7b6fb7f42143ce126d2b453022b08770da3af31ca2fdaaba

我不了解 CloudPanel,但错误消息似乎不言自明:

'if ENV["DISCOURSE_SMTP_ADDRESS"] == "smtp.example.com"; puts "Aborting! Mail is not configured!"; exit 1; end'
'if ENV[\"DISCOURSE_SMTP_ADDRESS\"] == \"smtp.example.com\"; puts \"Aborting! Mail is not configured!\"; exit 1; end'\"

看起来您的电子邮件在 ./discourse-setup 期间或在 app.yml 中未配置(您可以随时手动编辑它)。 :thinking:

2 个赞

各位老师,你们好!我是费米高中的一名教授,正在为我们学校安装 Discourse 社区。由于我们使用云面板,我遵循了本指南,但显然有些东西遗漏了。是否可以获得帮助和更详细的指南?非常感谢!

1 个赞

如果您没有多少系统管理知识,我认为使用高级安装可能不是您想要的。另一个需要考虑的重要问题是,此类安装将属于 unsupported-install,如果您遇到问题,在此处获得帮助的可能性会降低。

如果您有预算,并且取决于您的社区规模,最好在另一台服务器上托管 Discourse 并遵循标准安装。

1 个赞

抱歉,像这样的服务有什么用?在我看来,也许指南不够详细,它是为系统管理员准备的,只需指出各个步骤就足够了。在我们那里有句话说:没有人天生就受过教育。感谢您的帮助和您的时间。

1 个赞

你说得对。这就是为什么推荐标准安装。

而且,@denvergeeks,这就是为什么我一开始就不认为创建这样的指南是个好主意。它很难编写,很难维护,而且只有你能检查它。

4 个赞

抱歉,我不同意。我已经在使用带有各种域名的Cloud Panel,此外,Discourse社区将放在一个子域上,那么作者的前提就非常清楚了(本指南适用于在VPS上安装了各种服务的Cloud Panel用户)。只需要稍微努力一下,就可以更好地详细说明一切。毕竟,知识共享是社区的基础,否则我就会购买已经安装并准备好使用的软件了。总之,我不想打扰任何人,如果可能的话,请提供帮助,谢谢,否则我将不再打扰您。

1 个赞

@denvergeeks 设置电子邮件对于正常运行至关重要,尽管有一个指向标准安装的链接,但该指南目前的写法绕过了电子邮件的设置以及可能对某些设置重要的其他杂项信息。

我想知道是否值得将“安装 Discourse”到“引导应用程序”部分替换为更类似以下内容的内容:

安装和配置 Discourse

按照 标准安装 的第 1-6 步进行操作

<在“编辑 app.yml 文件”中执行当前操作>

重新构建 Discourse:

./launcher rebuild app

然后在“恭喜!”部分,在屏幕截图后添加一行,说明“继续完成标准的其余安装文档。”本质上是重新构建指南,提供补充标准安装的额外步骤,而不是提供替代的安装说明。

我认为您提供的关于 CloudPanel 的信息非常有价值,并且说明很清晰,Discourse 部分可以减少与标准安装的偏差,使其更安全,并使用 unsupported-install 标签来明确(更清晰)此处有风险。

2 个赞

[quote=“Antonio Cirillo, post:18, topic:266422, username:Antonio_Cirillo”]
毕竟,知识共享是社区的基础,否则我早就买了现成的软件了。总之,我不想打扰任何人,如果能得到帮助,我将不胜感激,否则我将不再打扰。
[/quote]讨论有点偏离了最初的话题,但请放心,我们很乐意提供帮助。 :slight_smile:

总结一下:

如果您具备基本的 IT 知识,可以按照标准安装流程进行。您还需要一个域名,并配置一个电子邮件发送服务,例如 Mailgun(教程链接:Configure Mailgun for email when using Digital Ocean for DNS

请注意,我们通常不会帮助处理超出本论坛范围的事宜。例如,“如何注册域名?”这个问题就不适合在这里讨论。

如果您不具备基本的 IT 知识,并且取决于您的预算,您可以在 Marketplace 上寻求付费支持。

最后,您还可以查看 Discourse 的托管付费计划,其中几乎所有内容都将由我们处理,您还可以获得我们的团队支持。

另外,请注意,鉴于您提到这是为您的学校服务的,我们为教育目的提供折扣:

是否有教育或非营利组织折扣?

是的!如果您被合法认定为教育机构,我们提供 85% 的折扣。如果您被合法认定为免税的非营利组织,我们提供 50% 的折扣。这些折扣仅适用于我们的基础版、专业版和商业版计划,不能与其他折扣合并使用,并且必须通过借记卡/信用卡按月或按年支付。请在开始试用后联系我们,我们将为您添加折扣。

4 个赞