Deploy Code Server on Ubuntu

https://github.com/coder/code-server

1. Intall

1
2
3
# install script
curl -fsSL https://code-server.dev/install.sh | sh
sudo systemctl enable --now code-server@$USER

2. Configure

1
vim  ~/.config/code-server/config.yaml

Set 0.0.0.0 to allow any IP to visit.

1
2
3
4
bind-addr: 0.0.0.0:8080
auth: password
password: 123456
cert: false

1
systemctl restart code-server@$USER

3. Reverse Proxy with Caddy

1
2
3
4
5
6
# install
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
1
2
# Config
vim /etc/caddy/Caddyfile
1
2
3
4
code.your.domain
{
reverse_proxy localhost:8080
}
1
2
3
4
# run Caddy as service
# https://github.com/caddyserver/dist/blob/master/init/caddy.service
vim /etc/systemd/system/caddy.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# caddy.service
#
# For using Caddy with a config file.
#
# Make sure the ExecStart and ExecReload commands are correct
# for your installation.
#
# See https://caddyserver.com/docs/install for instructions.
#
# WARNING: This service does not use the --resume flag, so if you
# use the API to make changes, they will be overwritten by the
# Caddyfile next time the service is restarted. If you intend to
# use Caddy's API to configure it, add the --resume flag to the
# `caddy run` command or use the caddy-api.service file instead.

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target

[Service]
Type=notify
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile --force
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateDevices=yes
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target
1
2
sudo systemctl enable --now caddy
systemctl status caddy

4. Set subdomain DNS

Add CNAME record in DNS

Name: code
value: your.domain

It’s all set now. Visit code.your.domain and test.