暗黑模式
前端静态页面
Deploy
- Use
caddy
to serve built files and proxy api to backend- Server system: ubuntu20+
Install caddy
Mare sure 80/443 ports aren't been used.
bash
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
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 # After installed, caddy will be automatically started, listening 80/443 port
# Check whether the installation is successful
systemctl status caddy
● caddy.service - Caddy
Loaded: loaded (/usr/lib/systemd/system/caddy.service; enabled; preset: enabled)
Active: active (running) since Wed 2024-10-16 19:06:58 CST; 46s ago
...
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
Refer: install caddy on ubuntu
Config caddy to serve built files
- Copy built files which located at the
dist
directory to server:
bash
# On dev computer
tar czf berry-ui-pro-dist.gz dist/ # package
scp ./berry-ui-pro-dist.gz xxx@xxx.xxx.xxx.xxx:~ # copy file to server
# On server computer
sudo mv berry-ui-pro-dist.gz /usr/share/caddy/ # move file to anywhere you like
cd /usr/share/caddy/
sudo tar xzf berry-ui-pro-dist.gz # unpackage
sudo mv dist/ berry-ui-pro-dist # rename dist to berry-ui-pro-dist(you can change this any way you like)
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
- Open caddy config file:
bash
vim /etc/caddy/Caddyfile
1
- Edit the config file:
# change `xxx.teclub.com` to your real domain, notice: make sure you have setting your domain's A/AAAA records point to this server's public ip.
xxx.teclub.com {
# Set this path to your site's directory.
root * /usr/share/caddy/berry-ui-pro-dist # Notice: this path points to your built files
# Enable the static file server.
file_server
# Set up a reverse proxy:
handle_path /proxy-api/* {
reverse_proxy http://test-erp.teclub.cn:5057
}
# If no static file matched, then redirect to index page, useful when serving spa with history route mode
handle /* {
try_files {path} {path}/ /index.html?{query}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- Reload caddy
bash
sudo systemctl reload caddy
1
Finally, navigate browser to xxx.teclub.com