2018/05/04

How to install Rocket.Chat on Ubuntu Server 16.04

Install required packages
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
apt update
apt install -y graphicsmagick build-essential mongodb-org nodejs

Start MongoDB
systemctl start mongod
systemctl enable mongod

Download and install Rocket.Chat
cd /opt
wget https://cdn-download.rocket.chat/build/rocket.chat-0.64.0.tgz
tar xzf rocket.chat-0.64.0.tgz
mv bundle Rocket.Chat
cd Rocket.Chat/programs/server
npm install
cd ../..
export ROOT_URL=http://localhost/
export MONGO_URL=mongodb://localhost:27017/rocketchat
export PORT=3000
node main.js


Ctrl+C to stop service

Install Nginx and add SSL key
apt -y install nginx
mkdir -p /etc/nginx/ssl/
cd /etc/nginx/ssl
openssl req -new -x509 -days 365 -nodes -out /etc/nginx/ssl/rocketchat.crt -keyout /etc/nginx/ssl/rocketchat.key
chmod 400 rocketchat.key

Add website config
nano /etc/nginx/sites-available/rocketchat

# Upstreams
upstream backend {
    server 127.0.0.1:3000;
}

# Redirect Options
server {
  listen 80;
  server_name localhost;
  # enforce https
  return 301 https://$server_name$request_uri;
}

# HTTPS Server
server {
    listen 443;
    server_name localhost;

    error_log /var/log/nginx/rocketchat.access.log;

    ssl on;
    ssl_certificate /etc/nginx/ssl/rocketchat.crt;
    ssl_certificate_key /etc/nginx/ssl/rocketchat.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # dont use SSLv3 ref: POODLE

    location / {
        proxy_pass http://127.0.0.1:3000/;
        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;
    }
}

Run nginx test and restart
nginx -t
systemctl restart nginx

Add startup script
ln -s /etc/nginx/sites-available/rocketchat /etc/nginx/sites-enabled/rocketchat

Run Rocket.Chat

cd /opt/Rocket.Chat/
export ROOT_URL=https://localhost/
export MONGO_URL=mongodb://localhost:27017/rocketchat
export PORT=3000
node main.js

Add background script
nano rocketchat.sh

#!/bin/bash
export ROOT_URL=https://localhost/
export MONGO_URL=mongodb://localhost:27017/rocketchat
export PORT=3000
node main.js &

chmod +x rocketchat.sh
./rocketchat.sh

沒有留言:

張貼留言