When installing Rocket.Chat, you need to set up SSL, either a free certificate or a purchased one. Now I should show you that you can use Let's Encrypt, a completely free SSL service. The default validity period of this certificate is 3 months. However, I have set up automatic renewal on my server. If your server is on a local network, you must therefore use NAT to forward the ports.
NAT PORT 443 (LAN) ➺ 443 (WAN) << Permanent
NAT PORT 80 (LAN) ➺ 80 (WAN) << Only before the SSL installation
My public IP address: 45.251.231.171
My local IP address: 10.66.30.10
Step # 01: You must update and upgrade the server, then install the nginx web server.
root@Rocket-Chat:~# apt-get update
root@Rocket-Chat:~# apt-get install software-properties-common python-software-properties
root@Rocket-Chat:~# apt-get install nginx
root@Rocket-Chat:~# systemctl status nginx.service
Before installing SSL, you must free port 80 on your server.
root@Rocket-Chat:~# netstat -pan | grep ":80"
root@Rocket-Chat:~# pkill -f nginx
root@Rocket-Chat:~# systemctl start nginx.service
root@Rocket-Chat:~# systemctl status nginx.service
Step # 02: Now install Let's Encrypt and certbot, and configure the nginx web server.
root@Rocket-Chat:~# add-apt-repository ppa:certbot/certbot root@Rocket-Chat:~# apt-get update
root@Rocket-Chat:~# apt-get install letsencrypt
root@Rocket-Chat:~# wget https://dl.eff.org/certbot-auto -P /usr/local/bin
root@Rocket-Chat:~# chmod a+x /usr/local/bin/certbot-auto root@Rocket-Chat:~# export DOMAIN="chat.kockerim.com" root@Rocket-Chat:~# export EMAIL_ALERT="admin@kockerim.com"
Step # 03: Install a free SSL certificate from Let's Encrypt for the nginx server.
root@Rocket-Chat:~# /usr/local/bin/certbot-auto certonly --standalone -d $DOMAIN --preferred-challenges http --agree-tos -n -m $EMAIL_ALERT --keep-until-expiring
Back up the old nginx web configuration file and edit it to use SSL.
root@Rocket-Chat:~# cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.back
root@Rocket-Chat:~# nano /etc/nginx/sites-available/default
Step # 04: Leave all the previous lines in place and add the following below all of them. And change the domain name for the SSL config.
Upstream definition
upstream backend {
server 127.0.0.1:3000;
}
http to https redirection
server {
listen 80;
server_name chat.kockerim.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
HTTPS Server
server {
listen 443;
server_name chat.kockerim.com;
error_log /var/log/nginx/rocket-chat.access.log;
ssl on;
ssl_certificate /etc/letsencrypt/live/chat.kockerim.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/chat.kockerim.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # don’t use SSLv3 ref: POODLE
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;
}
}
Step # 05: Restart the nginx web server and run the renew command.
root@Rocket-Chat:~# nginx -t
root@Rocket-Chat:~# service nginx restart
root@Rocket-Chat:~# certbot-auto renew