Static WebHost
Author: Serein-213
Deploy static files to Caddy or Nginx. Auto-detects which server is available.
Step 0: Detect Web Server
Before deploying, detect which web server is installed and running:
CODEBLOCK0
Priority: Caddy (if both are running) > Nginx > Neither (prompt user to install one).
Caddy Deployment
Setup (first time only)
Ensure Caddyfile has a static file block. Add if missing:
CODEBLOCK1
Then systemctl reload caddy.
Deploy
CODEBLOCK2
URL: INLINECODE1
No reload needed — files are served instantly.
Nginx Deployment
Setup (first time only)
Create a location block in the Nginx site config (e.g. /etc/nginx/sites-available/default or /etc/nginx/conf.d/static.conf):
CODEBLOCK3
Then nginx -t && systemctl reload nginx.
Deploy
CODEBLOCK4
URL: INLINECODE5
No reload needed — files are served instantly once placed in web root.
Common Steps (both servers)
Get access URL
CODEBLOCK5
Verify
CODEBLOCK6
Expect 200.
Notes
- - Web root:
/var/www/html/ (shared convention for both Caddy and Nginx) - URL pattern:
http://<ip>/r/<subdir>/ (consistent across both servers) - Files are served instantly — no reload needed after placing files
- For subdirectories, ensure
index.html exists - Large files (>50MB) should be considered carefully for disk usage
- If neither Caddy nor Nginx is installed, suggest
pacman -S caddy / apt install caddy / INLINECODE12
静态网页托管
作者: Serein-213
将静态文件部署到 Caddy 或 Nginx。自动检测可用的服务器。
第 0 步:检测 Web 服务器
在部署之前,检测已安装并正在运行的 Web 服务器:
bash
检查 Caddy
command -v caddy && systemctl is-active caddy 2>/dev/null
检查 Nginx
command -v nginx && systemctl is-active nginx 2>/dev/null
优先级: Caddy(如果两者都在运行)> Nginx > 均未运行(提示用户安装一个)。
Caddy 部署
设置(仅首次)
确保 Caddyfile 包含静态文件块。如果缺少则添加:
:80 {
handle_path /r/* {
file_server {
root /var/www/html
}
}
}
然后执行 systemctl reload caddy。
部署
bash
mkdir -p /var/www/html/<项目名称>
cp -r <源文件> /var/www/html/<项目名称>/
URL: http:///r/<项目名称>/index.html
无需重新加载——文件可立即提供服务。
Nginx 部署
设置(仅首次)
在 Nginx 站点配置中创建一个 location 块(例如 /etc/nginx/sites-available/default 或 /etc/nginx/conf.d/static.conf):
nginx
server {
listen 80;
# ... 现有配置 ...
location /r/ {
alias /var/www/html/;
autoindex off;
try_files $uri $uri/ =404;
}
}
然后执行 nginx -t && systemctl reload nginx。
部署
bash
mkdir -p /var/www/html/<项目名称>
cp -r <源文件> /var/www/html/<项目名称>/
URL: http:///r/<项目名称>/index.html
无需重新加载——文件放置到 Web 根目录后即可立即提供服务。
通用步骤(两种服务器)
获取访问 URL
bash
Tailscale
tailscale ip -4 2>/dev/null
或本地 IP
hostname -I | awk {print $1}
验证
bash
curl -s -o /dev/null -w %{http_code} http://127.0.0.1:80/r/<项目名称>/index.html
预期返回 200。
注意事项
- - Web 根目录: /var/www/html/(Caddy 和 Nginx 的通用约定)
- URL 模式: http:///r/<子目录>/(两种服务器保持一致)
- 文件可立即提供服务——放置文件后无需重新加载
- 对于子目录,请确保存在 index.html
- 大文件(超过 50MB)应谨慎考虑磁盘使用情况
- 如果既未安装 Caddy 也未安装 Nginx,建议执行 pacman -S caddy / apt install caddy / apt install nginx