ブラウザで VS Code が使用できるサービスに Github Codespaces があります。無料枠があって大変重宝しているのですが、ずっと起動したままにできません。そこで OCI の無料インスタンスを使用して、無料の SSL/TLS 証明書を用意して、自分専用の code-server を作ってみました。
なお、事前に OCI インスタンスのパブリック IP アドレスの名前解決と、VCN のセキュリティリストで 80 と 443 ポートにアクセスできるようにしておく必要があります。
OCI のインスタンスに SSH 接続
ssh ubuntu@<instance ip address>
無料の SSL/TLS 証明書を用意
sudo apt update
sudo apt install -y nginx certbot python3-certbot-nginx firewalld
sudo firewall-cmd --zone=public --permanent --add-port=80/tcp
sudo firewall-cmd --zone=public --permanent --add-port=443/tcp
sudo firewall-cmd --reload
sudo certbot --non-interactive --redirect --agree-tos --nginx -d <my fqdn domain> -m <my email address>
code-server のインストールと設定
curl -fsSL https://code-server.dev/install.sh | sh
sudo systemctl enable --now code-server@$USER
sudo systemctl status code-server@$USER
sudo vi /etc/nginx/sites-available/default
server_name <my fqdn domain>;
location / {
proxy_pass http://localhost:8080/;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Accept-Encoding gzip;
}
sudo nginx -t
sudo nginx -s reload
ブラウザから code-server にアクセス

参考
https://coder.com/docs/code-server/latest/guide#using-lets-encrypt-with-nginx
タグ: code-server, OCI