Setup Discourse Forum Software on your new server or with your existing websites running NGINX or APACHE web server

Tutorials

Discourse has gained a great reputation over the years as it is a free, open source, new generation, feature-rich and remarkable community-oriented forum software. It is different to existing forum software due to its amazing features like large social networks.

We discovered that it could be a frustration process to get it running with your existing website. You can contact us directly via our Contact Page to get our Professional Setup of Discourse Forum software on you new or existing server.

 

Prerequisite.

· A fresh web server or your existing server hosting your websites.

·         Setup correct DNS for your domain or subdomain where you want Discourse Forum software to be installed.

Note: This guide can be used in Debian or Ubuntu Linux environment. You can also implement it on CentOS and other distributions by using their dedicated commands.

 

To begin;

 

1.       Server access and Setup for Discourse Forum Software

Use an SSH server tool such as putty to access your server. You will be using Linux commands in this step and therefore a good knowledge of Linux is required to complete this process. Firstly, you must ensure that you change the hostname of your server to the correct one to be used by your system. As soon as you are ready, you might have to assign a certain amount of disk space or Setup swap for your Discourse Forum website.

To assign disk space or swap (Let’s say 1GB), you can create an empty swap file by following the command instructions below;

 $ install -o root -g root -m 0600 /dev/null /swapfile

Then, you will write out a 1GB file named swapfile by running;

dd if=/dev/zero of=/swapfile bs=1k count=1024k

Next, you must tell the system that this is the swap file by running;

$ mkswap /swapfile

After letting the system know that you are dealing with a swap file, you need to simply activate it by using;

$ swapon /swapfile

It is important to add the swap file to the system table so that it is available after reboot. Use the command below;

$ echo "/swapfile swap swap auto 0 0" | tee -a
/etc/fstab

Now its time to set the swappiness so that it is only used as an emergency buffer. Apply the following command;

$ sysctl -w vm.swappiness=10

Next we can start the Discourse installation proper. To get Discourse installed successfully, you need to get some properties ready such as GIT and the Docker itself.

To get Git installed, run the following;

 

$ apt update
$ apt install git -y

Next, you can install Docker by using by running the following individually;

$ wget -qO- https://get.docker.com/ | sh
$ sudo apt-get update
$ sudo apt-get install -y docker-ce
$ sudo systemctl status docker

Then, you will make a folder called discourse in the /var directory by running;

$ mkdir /var/discourse

Next, you should clone the official Discourse Git repository into /var/discourse via;

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

Now, change your working directory into the discourse directory:

$ cd /var/discourse

Before, running Discourse setup tool, if your web server is already listening to port 80 and 443, you must stop them first before you continue!

Use the port check tool by running;

$ netstat -plntu

or

$ sudo netstat -tulpn

If you are installing on a fresh server, you do not have to worry about this.

Next, you can launch the setup tool:

$ ./discourse-setup

You will have to complete all the further instructions required to complete the setup, such as your Discourse hostname, email and so on.

After the setup process has completed, an app.yml configuration file will be generated, and this is in the /var/discourse/containers Directory.

Note: If you need to modify the configuration settings after bootstrapping, edit your /containers/app.yml file and run ./launcher rebuild app. Otherwise, your changes will not take effect.

 

Congratulations, you now have your own instance of Discourse up and running. To access it, simply type the discourse hostname (http://hostname.anydomain.com) you have configured into a web browser and complete the configuration for your new Forum website.

 

2.       Further Discourse Configuration with your existing website

Since discourse works on your web server’s port by default, there is need to configure it outside your web services docker container to prevent any form of issues with your website and to ensure that the installation goes through smoothly.

This process can be implemented on both APACHE and NGINX web server. But for the purpose of this tutorial, we will configure it to work with NGINX.

As earlier stated, we need to configure the web server outside the container

First, ensure that the container is not running. Use the command below;

$ cd /var/discourse
$ ./launcher stop app

Then, you should edit and set the templates and ports in the Discourse's environment configuration file (/var/discourse/containers/app.yml).

You can use the following directives as a template;

templates:

  - "templates/postgres.template.yml"

  - "templates/redis.template.yml"

  - "templates/sshd.template.yml"

  - "templates/web.template.yml"

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

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

## Uncomment these two lines if you wish to add Lets Encrypt (https)

  #- "templates/web.ssl.template.yml"

  #- "templates/web.letsencrypt.ssl.template.yml"

 

## which TCP/IP ports should this container expose?

## If you want Discourse to share a port with another webserver like Apache or nginx,

## see https://meta.discourse.org/t/17247 for details

## expose:

  ## - "80:80"   # http

  ## - "443:443" # https

 

Next, you can create a NGINX 'site' for the external nginx. Create a "discourse.conf" file in the /etc/nginx/sites-enabled/ directory as follows:

· For a http website, this is just a template for our illustration;

server {

                listen 80; listen [::]:80;

                server_name hostname.anydomain.com;  # <-- change this

 

                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;

                }

}

 

For an HTTPS site, use the configuration below;

 

server {

    listen 80; listen [::]:80;

    server_name hostname.anydomain.com;  # <-- change this

 

    return 301 https://$host$request_uri;

}

 

server {

    listen 443 ssl http2;  listen [::]:443 ssl http2;

    server_name hostname.anydomain.com;  # <-- change this

 

    ssl_certificate      /var/discourse/shared/standalone/ssl/ssl.crt;

    ssl_certificate_key  /var/discourse/shared/standalone/ssl/ssl.key;

    ssl_dhparam          /var/discourse/shared/standalone/ssl/dhparams.pem;

    ssl_session_tickets off;

    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA;

 

    http2_idle_timeout 5m; # up from 3m default

 

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

        proxy_set_header X-Real-IP $remote_addr;

    }

}

Note that you can generate a "dhparams.pem key file"  (dh stands for Diffie Hellman) by using;

openssl dhparam -out
/var/discourse/shared/standalone/ssl/dhparams.pem 2048

As earlier advised Make sure that Discourse isn't running. Check by running;

$ /var/discourse/launcher stop app || true

Then you can test your NGINX configuration for any errors;

$ sudo nginx -t

Should you experience an error while running the above NGINX error check command (nginx -t), make sure you correct the config before reloading!

If it goes successfully, reload via;

$ sudo service nginx reload

Finally, you can Rebuild the Discourse container to apply changes by running;

$ /var/discourse/launcher rebuild app

Now you can access your Discourse Forum website via your forum website link as declared.

We offer a professional installation of Discourse community forum software, reach out to us as we offer a wide range of Linux Management services at fair minimum rate with free support for one month via email. You can Request Installation Service Now.

 

 


Conclusion

Discourse is an easy to use forum software which is great if your want to setup a discussion forum for your new or existing website.

Your Cart