BobbyQuineのブログ(備忘録)

Linux関係の備忘録、その他タバコ、Vape関連なんかも。

Ubuntu Server 20.04 LTSにRocket.Chatを入れる(ただの備忘録,不正確な可能性あり)MyDNS.jpの無料ドメインでLet's Encrypt

参考にしたページ

https://qiita.com/bibimarujp/items/b1bebba9dd67422031c6

https://docs.rocket.chat/installing-and-updating/manual-installation/configuring-ssl-reverse-proxy

https://docs.rocket.chat/installing-and-updating/manual-installation/ubuntu

https://www.mydns.jp/members/#domaininfo

GitHub - disco-v8/DirectEdit: These are scripts for users of MyDNS.JP and are necessary to obtain server certificates with Let's Encrypt's DNS-01.

 

UbuntuとRocket.Chatのインストール

Proxmox上にUbuntu server 20.04 LTSをインストールし,そこにRocket.Chatを入れていく.Ubuntu Serverのインストールディスクを選択して起動,ある程度設定決めたところで「なにかサードパーティソフト入れる?」的な選択肢が出てくる.その中にRocket.Chatがあるのでチェック入れてインストールする(その画像に関しては上記参考ページのqiitaのものを参考にしてください).

すでに動いているUbuntu Server の場合は公式のインストール方法みるのが正解.

 

Rocket.Chatの初期設定

LAN内で作業.作業端末のブラウザでRocket.Chatの鯖の3000番ポートにアクセス.

初期設定をやる.このへん参照.プライベート用途だった場合「登録」項目はしっかり弄った方がいい.

https://www.itcore.jp/tips/rocketchat.php

 

 Let's Escrypt

まず,ドメインが必要.私は動的グローバルIPの回線しか持っていないのでDynamic DNSに登録する必要がある.今回はMyDNS.jpさんを利用させていただいた.

Let's Escryptでの証明書発行についてGitHubに公開されていて非常にやりやすい.

無料ドメインの枠を使わせていただいた.ここでは????????.&&&&&&.mydns.jpとする.

ポートフォワーディングに関しては自分でやって.この時点で外から見たときの80番と443番は開いとく.

 

Ubuntu Serverにて

 

# apt install nginx certbot python3-certbot-nginx php php-mbstring unzip vim

# systemctl start nginx

もしnginxが立ち上がらなかったらたぶんApacheが邪魔してる.Ubuntuのインストールすると初期設定で自動起動有効なのほんと嫌い.私の環境ではいつ紛れ込んだのか分からないけれどもApacheが入ってて設定途中に再起動したらApache立ち上がってNginx立ち上がらなくなってた.

# systemctl disable apache2.service

# systemctl stop apache2.service

 

# mkdir /root/SSL

# cd /root/SSL

# wget 'https://github.com/disco-v8/DirectEdit/archive/master.zip' -O DirectEdit-master.zip

# unzip DirectEdit-master.zip

# cd DirectEdit-master

# chmod 700 ./*.php

# chmod 600 ./*.conf

# vim txtedit.conf

$MYDNSJP_MASTERID = 'yourmasterid';
$MYDNSJP_MASTERPWD = 'yourpasswd';
$MYDNSJP_DOMAIN = '????????.&&&&&&.mydns.jp';

 

# sudo certbot certonly --manual --preferred-challenges=dns --manual-auth-hook /root/SSL/DirectEdit-master/txtregist.php --manual-cleanup-hook /root/SSL/DirectEdit-master/txtdelete.php -d ????????.&&&&&&.mydns.jp --server https://acme-v02.api.letsencrypt.org/directory --agree-tos -m your@mailaddress --manual-public-ip-logging-ok

 

もしかしたらこのコマンド前にnginx一回立ち上げとかなきゃかも.その場合

# systemctl start nginx

 

出来た公開鍵は/etc/letsencrypt/live/????????.&&&&&&.mydns.jp/fullchain.pem

秘密鍵は/etc/letsencrypt/live/????????.&&&&&&.mydns.jp/privkey.pem

 

# vim /etc/nginx/sites-enabled/default

Upstreams
upstream backend {
server 127.0.0.1:3000;
}

# HTTPS Server
server {
listen 443;
server_name ????????.&&&&&&.mydns.jp;

# You can increase the limit if your need to.
client_max_body_size 200M;

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

ssl on;
ssl_certificate /etc/letsencrypt/live/????????.&&&&&&.mydns.jp/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/????????.&&&&&&.mydns.jp/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-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Nginx-Proxy true;

proxy_redirect off;
}
}

 

書き終わったら

# systemctl restart nginx

自動起動にするために

# systemctl enable nginx

 

おそらくこれで "別回線" から????????.&&&&&&.mydns.jpにアクセスすればhttpsでRocketChatにアクセスできる.オレオレ証明ではないのでAndroidアプリからもアクセス可能となる.

 

今回の教訓 Ubuntuはなんでもかんでも勝手に立ち上げる.殺せ.