5.2 KiB
5.2 KiB
DevBox 服务器部署
一条命令搞定,跟宝塔面板的安装方式一样:SSH 连上服务器,粘一行,回车。
curl -fsSL https://raw.githubusercontent.com/syc65535/devbox/main/install.sh | sudo bash
跑完会打印访问地址,默认 http://服务器IP:8090/。
想换端口、换目录,在后面加参数(见下方「参数」)。 没装 sudo 的机器用
su -切到 root 再跑,或者把sudo bash换成bash。
它做了什么
- 检查 root,缺
git/curl/python3就用 apt / dnf / yum / apk 自动装 - 把仓库浅克隆到
/opt/devbox(已存在就fetch + reset --hard更新) - 写
systemd服务devbox.service,用 Python 自带的静态服务器跑,Restart=always curl健康检查,确认页面能打开- 可选:写一份 Nginx 站点配置并 reload
装完这些命令都能用:
systemctl status devbox # 看状态
journalctl -u devbox -f # 看日志
systemctl restart devbox # 重启
参数
curl -fsSL https://raw.githubusercontent.com/syc65535/devbox/main/install.sh | sudo bash -s -- [参数]
| 参数 | 说明 | 默认 |
|---|---|---|
--port 8080 |
HTTP 端口 | 8090 |
--dir /srv/devbox |
安装目录 | /opt/devbox |
--nginx box.example.com |
同时写 Nginx 站点并 reload(_ 表示默认站点) |
不写 |
--no-service |
只拉代码,不装 systemd(容器、没 systemd 的机器) | 关 |
--update |
更新到最新代码并重启 | — |
--uninstall |
停服务、删 unit 和 Nginx 配置(保留代码目录) | — |
-h |
帮助 | — |
例子:
# 换端口
curl -fsSL https://raw.githubusercontent.com/syc65535/devbox/main/install.sh | sudo bash -s -- --port 8080
# 装到 /www/wwwroot/devbox,并挂一个域名
curl -fsSL https://raw.githubusercontent.com/syc65535/devbox/main/install.sh | sudo bash -s -- \
--dir /www/wwwroot/devbox --port 8080 --nginx box.example.com
# 更新
curl -fsSL https://raw.githubusercontent.com/syc65535/devbox/main/install.sh | sudo bash -s -- --update
# 卸载
curl -fsSL https://raw.githubusercontent.com/syc65535/devbox/main/install.sh | sudo bash -s -- --uninstall
宝塔面板
两种都行:
A. 用面板自带的终端(推荐)
面板 → 终端(或 SSH 工具),直接粘上面那条一键命令。脚本和宝塔不冲突,走的是 systemd,不占面板的站点。
B. 用面板建个纯静态站点
- 面板 → 网站 → 添加站点,域名填你的域名,PHP 版本选「纯静态」
- 把仓库代码放进站点根目录(面板 → 文件 → 上传,或终端执行):
cd /www/wwwroot/你的域名 && git clone --depth=1 https://github.com/syc65535/devbox.git . - 面板 → 网站 → 设置 → 网站目录,确认根目录对上,保存
- 需要 HTTPS 就在面板 → SSL 里申请 Let's Encrypt 证书,一键部署
纯静态站点不需要 Node、不需要数据库,也不吃 CPU。
Nginx + HTTPS(不用宝塔时)
脚本带 --nginx 域名 会自动写好 /etc/nginx/conf.d/devbox.conf。之后:
sudo apt install -y certbot python3-certbot-nginx # Debian/Ubuntu
sudo certbot --nginx -d box.example.com --redirect
不用 Nginx 也能跑:脚本起的 8090 端口本身就是 HTTP 服务,直接访问 IP 即可。
手动部署(不用脚本)
DevBox 是纯静态页面,任何静态托管都能放:
git clone --depth=1 https://github.com/syc65535/devbox.git
cd devbox
python3 -m http.server 8090
# 打开 http://127.0.0.1:8090
也可以丢给 GitHub Pages、Cloudflare Pages、Vercel,或者公司内网的 Nginx / Caddy,指向目录即可,不用构建。
常见问题
打不开 / 一直在转
- 云服务器要在「安全组」里放行端口,本机防火墙也要放行:
ufw allow 8090/tcp - 看服务活着没:
systemctl status devbox;看报错:journalctl -u devbox -n 50 --no-pager - 端口被占用:换
--port 8081再装一遍,脚本是幂等的
想用 80 端口
加 --nginx 域名,用 Nginx 反代/静态托管到 80/443,脚本自己的 8090 只监听本机也行(把 unit 里的 0.0.0.0 改成 127.0.0.1)。
服务器是 Docker / 没 systemd
用 --no-service 只拉代码,然后自己起:
docker run -d --name devbox -p 8090:80 \
-v /opt/devbox:/usr/share/nginx/html:ro nginx:alpine
怎么更新到最新版
curl -fsSL https://raw.githubusercontent.com/syc65535/devbox/main/install.sh | sudo bash -s -- --update
私有仓库
把 REPO_URL 换掉再跑:
curl -fsSL https://raw.githubusercontent.com/syc65535/devbox/main/install.sh | \
sudo DEVBOX_REPO=https://<token>@github.com/你/仓库.git bash
会不会收集数据
不会。页面全在浏览器里算,服务端只是个静态文件服务器。
目录
装完之后是这些文件,升级只会覆盖代码,不动配置:
/opt/devbox/
├── index.html
├── css/ js/ preview/
└── README.md
/etc/systemd/system/devbox.service # 服务
/etc/nginx/conf.d/devbox.conf # 只有加了 --nginx 才有