To Install a First Discourse Instance on CloudPanel
To Install a Second Discourse Instance on the Same CloudPanel Server…
1. Create a Reverse Proxy Site in CloudPanel
In CloudPanel…
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.
Next we click create a new “Create a Reverse Proxy” in the CloudPanel for the domain where we want to host our Discourse forum.
Here we type in the Domain Name for our Discourse forum. If we want, we can change the Site User and/or Site User Password, or just accept the defaults provided.
2. Prepare the Domain and Set up SSL (Cloudflare)
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.)
One more thing in Cloudflare, is to prevent the error …
… in Cloudflare we need to …
3. Create and Edit the app2.yml File
Next, back in Putty (or other terminal), as the root user… type
nano /var/discourse/containers/app2.yml
Enter
(This creates the app2.yml file.)
Now we paste in the contents of the below sample app2.yml file, and then edit according to our specific site settings:
Sample of app2.yml (w/Cloudflare & Mailgun) ->
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" db_shared_buffers: "4096MB" env: DISCOURSE_CAN_PERMANENTLY_DELETE: true LC_ALL: en_US.UTF-8 LANG: en_US.UTF-8 LANGUAGE: en_US.UTF-8 DISCOURSE_FORCE_HTTPS: true UNICORN_WORKERS: 8 DISCOURSE_HOSTNAME: 'domain.com' DISCOURSE_DEVELOPER_EMAILS: 'admin@domain.com' DISCOURSE_SMTP_ADDRESS: smtp.mailgun.org DISCOURSE_SMTP_PORT: 587 DISCOURSE_SMTP_USER_NAME: postmaster@domain.com DISCOURSE_SMTP_PASSWORD: xxxxxxxxxx DISCOURSE_NOTIFICATION_EMAIL: noreply@domain.com volumes: - volume: host: /var/discourse/shared/standalone2 guest: /shared - volume: host: /var/discourse/shared/standalone2/log/var-log guest: /var/log hooks: after_code: - exec: cd: $home/plugins cmd: - git clone https://github.com/discourse/docker_manager.git
Under the section env: we need to change both instances of domain.com to the domain name of our Discourse site;
→ Then we save and exit the app2.yml file…
CTRL-X
y
Enter
4. Set the Permissions for the app2.yml File
Next, still in the terminal, we set the permissions for the app2.yml file…
chmod o-rwx /var/discourse/containers/app2.yml
Enter
then…
5. Bootstrap the App
cd /var/discourse
Enter
./launcher bootstrap app2
Enter
This will take 5 - 10 minutes.
While we are waiting for the app to bootstrap, we…
6. Edit the Vhost File
Back in our CloudPanel site settings we paste the below Sample Vhost Contents into the “Vhost Editor” for our Discourse site (overwriting what is already there).
Sample Vhost Contents
server { listen 443 ssl http2; listen [::]:443 ssl http2; {{ssl_certificate_key}} {{ssl_certificate}} server_name domain.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/standalone2/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; } }
Of course we replace:
domain.com with the actual domain name of our new CloudPanel site from above.
(Then, don’t forget to Save the Vhost settings.)
7. Next, Launch Start
Back in the terminal, at the end of the bootstrap process, you’ll be asked if you want to (and you do, so type in)…
./launcher start app2
Enter
Sidenote: When using a Cloudflare Origin SSL Certificate I find that (for some unknown reason) I need to go into Cloudflare SSL and change the encryption mode to Full, and then back again to Full (Strict) to prevent an error (err_ssl_version_or_cipher_mismatch).
So…
And then…
Enjoy Your Second Discourse!
Go to the URL of your new site, and you should see this…
For More Discourse Instances…
Follow this tutorial, changing every instance of (for example) app2 to app3, app2.yml to app3.yml, and standalone2 to standalone3.
On your CloudPanel, using this method, you can install as many Discourse instances as your CloudPanel server can handle!
2023-09-29 Jen's Sample Contents for app9.yml
## 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
DISCOURSE_CAN_PERMANENTLY_DELETE: true
DISCOURSE_ENABLE_CORS: 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: 'domain.com'
## 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@domain.com'
## 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@domain.com
DISCOURSE_SMTP_PASSWORD: xxxxxxxxxxxx
#DISCOURSE_SMTP_ENABLE_START_TLS: true # (optional, default true)
#DISCOURSE_SMTP_DOMAIN: jen.do # (required by some providers)
DISCOURSE_NOTIFICATION_EMAIL: noreply@domain.com # (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/standalone9
guest: /shared
- volume:
host: /var/discourse/shared/standalone9/log/var-log
guest: /var/log
## Plugins go here
## see https://meta.discourse.org/t/19157 for details
hooks:
after_code:
- exec:
cd: $home
cmd:
- sudo apt-get install wget ca-certificates
- exec:
cd: $home
cmd:
- wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
- exec:
cd: $home
cmd:
- sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
- exec:
cd: $home
cmd:
- apt-get update
- exec:
cd: $home
cmd:
- apt-get -y install -y postgresql-server-dev-13
- exec:
cd: $home/tmp
cmd:
- git clone https://github.com/neondatabase/pg_embedding.git
- exec:
cd: $home/tmp/pg_embedding
cmd:
- make PG_CONFIG=/usr/lib/postgresql/13/bin/pg_config
- exec:
cd: $home/tmp/pg_embedding
cmd:
- make PG_CONFIG=/usr/lib/postgresql/13/bin/pg_config install
- exec:
cd: $home
cmd:
- su postgres -c 'psql discourse -c "create extension if not exists embedding;"'
- exec:
cd: $home/plugins
cmd:
- git clone https://github.com/discourse/docker_manager.git
- git clone https://github.com/discourse/discourse-ai.git
- git clone https://github.com/merefield/discourse-ai-topic-summary.git
- git clone https://github.com/discourse/discourse-akismet.git
- git clone https://github.com/denvergeeks/discourse-audio-message.git
- git clone https://github.com/discourse/discourse-bbcode.git
- git clone https://github.com/discourse/discourse-categories-suppressed.git
- git clone https://github.com/discourse/discourse-characters-required.git
- git clone https://github.com/merefield/discourse-chatbot.git
- git clone https://github.com/cpradio/discourse-plugin-composer-help-button.git
- git clone https://github.com/discourse/discourse-docs.git
- git clone https://github.com/discourse/discourse-follow.git
- git clone https://github.com/discourse/discourse-footnote.git
- git clone https://github.com/MonDiscourse/discourse-formatting-toolbar.git
- git clone https://github.com/discourse/discourse-gamification.git
- git clone https://github.com/paviliondev/discourse-group-directory.git
- git clone https://github.com/discourse/discourse-group-tag-associations.git
- git clone https://github.com/discourse/discourse-group-tracker.git
- git clone https://github.com/discourse/discourse-nested-posts.git
- git clone https://github.com/paviliondev/discourse-news.git
- git clone https://github.com/thoka/discourse-send-pdf-inline.git
- git clone https://github.com/discourse/discourse-plugin-autoplay.git
- git clone https://github.com/discourse/discourse-post-voting.git
- git clone https://github.com/discourse/discourse-prepend-tags-in-topic-slug.git
- git clone https://github.com/discourse/discourse-reactions.git
- git clone https://github.com/discourse/discourse-restricted-replies.git
- git clone https://github.com/discourse/discourse-rss-polling.git
- git clone https://github.com/discourse/discourse-saved-searches.git
- git clone https://github.com/discourse/discourse-solved.git
- git clone https://github.com/discourse/discourse-staff-alias.git
- git clone https://github.com/discourse/discourse-subscriptions.git
- git clone https://github.com/discourse/discourse-surveys.git
- git clone https://github.com/discourse/discourse-templates.git
- git clone https://github.com/discourse/discourse-tooltips.git
- git clone https://github.com/discourse/discourse-topic-voting.git
- git clone https://github.com/merefield/discourse-word-cloud.git
## Any custom commands to run after building
run:
- exec: echo "Beginning of custom commands"
- exec: rails r "SiteSetting.max_category_nesting=3"
- exec: rails r "SiteSetting.allow_embedding_site_in_an_iframe=true"
## 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"
2023-09-29 Jen's Sample Vhost Contents for app9
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
{{ssl_certificate_key}}
{{ssl_certificate}}
server_name domain.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/standalone9/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;
}
}