Multiple Instances of Discourse on CloudPanel

To Install a First Discourse Instance on CloudPanel


To Install a Second (and more) Discourse Instance on the Same Server

The process is mostly the same.

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

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’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.)

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

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

Edit the app2.yml File

nano /var/discourse/containers/app2.yml

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

Under the section templates: we need to add

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

Under the section expose: we need to comment out

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

Under the section env: (in addition to our site-specific settings) we need to add

   DISCOURSE_FORCE_HTTPS: true

Under the section volumes: we need to change both instances of standalone to standalone2

volumes:
  - volume:
      host: /var/discourse/shared/standalone2
      guest: /shared
  - volume:
      host: /var/discourse/shared/standalone2/log/var-log
      guest: /var/log
Click here for a sample of app.yml contents
## 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: 'jen.do'

  ## 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@jen.do'

  ## 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@jen.do
  DISCOURSE_SMTP_PASSWORD:  xxxxxxxxxx           # (password goes here)
  #DISCOURSE_SMTP_ENABLE_START_TLS: true           # (optional, default true)
  #DISCOURSE_SMTP_DOMAIN: jen.do    # (required by some providers)
  DISCOURSE_NOTIFICATION_EMAIL: noreply@jen.do    # (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 app2.yml file…

CTRL-X

y

Enter

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

chmod o-rwx /var/discourse/containers/app2.yml

then…

Bootstrap the App

cd /var/discourse
./launcher bootstrap app2

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

./launcher start app2

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/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;

  }
}

Restart Nginx

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

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 app2 to app3, app2.yml to app3.yml, and standalone2 to standalone3, and so forth.

On your CloudPanel, using this method, you can install as many Discourse instances as your server can handle!