How to install with nginx reverse proxy on Ubuntu 20.04

If you are searching for an open-source self-hosted chat platform then Rocketchat can be the best option. Rocket chat can be used as an alternative to different communication channels such as slack, mattermost etc. Rocket chat comes with different features such as group chats, video conferencing, and you can integrate live chat with other platforms. In this article, we will learn how to set up a self-hosted Rocketchat system with let’s encrypt SSL certificates.


  1. Fresh ubuntu server
  2. Root access or sudo privileged account
  3. A domain name pointed with server IP
  4. Internet connection to download applications

Install required packages and dependencies

Before installing the packages, update the Ubuntu system using the following command

$ sudo apt-get update -y

Once the system update is completed, configure apt to install MongoDB packages using the following command.

$ sudo apt-key adv --keyserver hkp:// --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
$ echo "deb [ arch=amd64 ] bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

Output :

Add Mongodb repository key

To configure Node.js to be able to install using apt package manager run the following command.

$ sudo apt-get -y update && sudo apt-get install -y curl && curl -sL | sudo bash -


Install Node.js

Now install the build tools Nodejs, MongoDB, and graphicsmagick :

$ sudo apt-get install -y build-essential mongodb-org nodejs graphicsmagick

Output :

Install graphicsmagick

Now install inherits and n, and the node version required by Rocketchat.

$ sudo npm install -g inherits n && sudo n 12.18.4

Install npm

To check the version of Nodejs installed, run the following command.

$ node --version



Install Rocketchat

We have already installed the required dependencies. Now in this step, we will download the Rocket Chat application and install it on Ubuntu 20.04.

Download the latest version of Rocketchat using the following command.

$ curl -L -o /tmp/
tar -xzf /tmp/ -C /tmp

Output :


Extract the downloaded application. You can choose your preferable directory to store the extracted file. In this example, I have extracted the file in the /tmp directory.

$ tar -xvzf /tmp/ -C /tmp

Now install Rocketchat. In this article /opt directory is used for installation. You can prefer any directory.

$ cd /tmp/bundle/programs/server && npm install


Unpack the archive and install Rocket Chat with npm package manager

$ sudo mv /tmp/bundle /opt/Rocket.Chat

Configure the Rocket.Chat service

Create a rocketchat user, set the correct permission to the Rocket.Chat application directory and create Rocket.Chat service.

$ sudo useradd -M rocketchat && sudo usermod -L rocketchat
$ sudo chown -R rocketchat:rocketchat /opt/Rocket.Chat

To create rocketchat.service, run the following command on your terminal

cat << EOF |sudo tee -a /lib/systemd/system/rocketchat.service
Description=The Rocket.Chat server nginx.service mongod.service
ExecStart=/usr/local/bin/node /opt/Rocket.Chat/main.js
Environment=MONGO_URL=mongodb://localhost:27017/rocketchat ROOT_URL=http://localhost:3000/ PORT=3000

Example: system file

Now we need to set up a MongoDB storage engine and replication. After this, enable and start mongoDB as:

$ sudo sed -i "s/^# engine:/ engine: mmapv1/" /etc/mongod.conf
$ sudo sed -i "s/^#replication:/replication:\n replSetName: rs01/" /etc/mongod.conf
$ sudo systemctl enable mongod && sudo systemctl start mongod
$ mongo --eval "printjson(rs.initiate())"

Output :

setup mongo.db

Now start and enable Rocket.Chat service using the following command:

$ sudo systemctl enable rocketchat && sudo systemctl start rocketchat

Verify the Rocket.Chat service status”

$ sudo systemctl status rocketchat


systemctl status rocketchat

Nginx installation and Reverse proxy configuration

To configure nginx reverse proxy for Rocket.Chat, install nginx using the following command

$ sudo apt install nginx

Create nginx virtual host configuration for rocketchat.

$ sudo nano /etc/nginx/conf.d/rocketchat.conf

Now paste the following contents and save the file

upstream backend {

server {
listen 80;

server_name your_rocketchat_domain_name;
access_log /var/log/nginx/;
error_log /var/log/nginx/;

location / {
proxy_pass http://backend/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forward-Proto http;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;

Check the nginx configuration file

$ sudo nginx -t

Configure nginx

Restart and enable nginx service

$ sudo systemctl restart nginx
$ sudo systemctl enable nginx

Now access your rocketchat domain as


You will get web setup wizard, complete it and start using Rocket.Chat

Nginx as SSL reverse proxy

We configured Rocket.Chat with only HTTP reverse proxy. To configure nginx as an SSL reverse proxy you will need certificate files. Edit the nginx vhost file and paste the following contents.

$ sudo nano /etc/nginx/conf.d/rocketchat.conf
upstream backend {

server {
listen 443 ssl;
Server_name your_rocketchat_domain_name;
client_max_body_size 200M;
access_log /var/log/nginx/;
error_log /var/log/nginx/;
ssl_certificate /etc/nginx/certificate.crt;
ssl_certificate_key /etc/nginx/private.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

location / {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;

Note :

Generate or purchase ssl certificate and point the directory of your certificate file in the following configuration parameter.

ssl_certificate /etc/nginx/certificate.crt; [Your certificate file]
ssl_certificate_key /etc/nginx/private.key; [Your Private Key file]

Check the nginx configuration file

sudo nginx -t

Restart nginx service

sudo systemctl restart nginx

Accessing Rocketchat

Once the reverse proxy is configured, you can access your Rocket.Chat using the URL as:


You will get Rocket.Chat web setup wizard. Complete the setup and start using your self-hosted Rocket.Chat.


In this article, we have learned how to install and configure self-hosted Rocket chat on Ubuntu 20.04. Also, I have covered how to install and configure nginx for reverse proxy with let’s encrypt SSL certificates.