目录

目录

Caddy部署前后端分离服务

目录

编写以下配置, 文件名 Caddyfile

:6006 {
	root * /home/guest/web/dist
	file_server
	encode zstd gzip

	handle_path /api/* {
		reverse_proxy localhost:6000
	}
}

启动命令为 caddy run --environ --config /home/guest/web/Caddyfile.

或者使用systemd管理服务启停, 编写如下配置文件, 命名为web-app.service:

[Unit]
Description=web-app
After=network.target

[Service]
Type=simple
WorkingDirectory=/home/guest/web
ExecStart=/home/guest/web/caddy_linux_amd64 run --environ --config /home/guest/web/Caddyfile
ExecReload=/home/guest/web/caddy_linux_amd64 reload --config /home/guest/web/Caddyfile
Restart=on-failure

[Install]
WantedBy=multi-user.target

放入/etc/systemd/system/, 如果没有root权限, 可以放入~/.config/systemd/user/, 编写完成使用systemctl命令管理服务.