skills/caddyfile-generation/SKILL.md
Generate Caddyfile configurations for static sites and reverse proxies — SPA fallback routing, cache headers, compression, redirects, and error pages. Use when deploying a static site that needs custom Caddy configuration, or when the user needs SPA routing, caching, or redirect rules.
npx skillsauth add nixopus/agent caddyfile-generationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
static-deploy or frontend builds)Minimal Caddyfile for a static site:
:80 {
root * /srv
file_server
}
Single-page apps need all non-file routes to return index.html:
:80 {
root * /srv
try_files {path} /index.html
file_server
}
Frameworks that need this: React (CRA, Vite), Vue, Angular, SvelteKit (static adapter), Remix (SPA mode).
Frameworks that do NOT need this: Next.js (has its own server), Nuxt (SSR), Astro (generates individual HTML files for each route).
Frontend build tools (Vite, Webpack) produce files with content hashes (e.g. main.a1b2c3.js). These can be cached aggressively:
:80 {
root * /srv
@hashed path_regexp hashed \.(js|css|woff2?|ttf|eot|svg|png|jpg|jpeg|gif|ico|webp)$
header @hashed Cache-Control "public, max-age=31536000, immutable"
@html path *.html /
header @html Cache-Control "no-cache, no-store, must-revalidate"
try_files {path} /index.html
file_server
}
HTML files must NOT be cached (they reference the hashed assets).
Enable gzip and zstd compression:
:80 {
root * /srv
encode zstd gzip
try_files {path} /index.html
file_server
}
www.example.com {
redir https://example.com{uri} permanent
}
example.com {
root * /srv
file_server
}
Caddy handles this automatically when using domain names. Only needed for explicit port-based configs:
:80 {
redir https://{host}{uri} permanent
}
Note: In Nixopus deployments, the proxy layer already handles TLS termination. Do NOT add HTTPS redirects in the app's Caddyfile — the proxy handles this.
:80 {
root * /srv
handle_errors {
@404 expression {err.status_code} == 404
rewrite @404 /404.html
file_server
}
try_files {path} /index.html
file_server
}
When a static frontend needs to proxy API requests to a backend:
:80 {
root * /srv
handle /api/* {
reverse_proxy backend:8080
}
try_files {path} /index.html
file_server
}
:80 {
root * /srv
header {
X-Content-Type-Options "nosniff"
X-Frame-Options "DENY"
Referrer-Policy "strict-origin-when-cross-origin"
-Server
}
file_server
}
Combines SPA routing, caching, compression, and security headers:
:80 {
root * /srv
encode zstd gzip
header {
X-Content-Type-Options "nosniff"
X-Frame-Options "DENY"
Referrer-Policy "strict-origin-when-cross-origin"
-Server
}
@hashed path_regexp hashed \.(js|css|woff2?|ttf|eot|svg|png|jpg|jpeg|gif|ico|webp)$
header @hashed Cache-Control "public, max-age=31536000, immutable"
@html path *.html /
header @html Cache-Control "no-cache, no-store, must-revalidate"
try_files {path} /index.html
file_server
}
try_files fallback) or multi-page (doesn't)try_files {path} /index.html if SPAencode zstd gzip for compressionCaddyfile at the project root:80 inside Docker — the proxy layer handles external port mapping and TLStry_files must come BEFORE file_server in the Caddyfileroot * /srv must match the COPY destination in the Dockerfilefile_server serves directory listings by default — add file_server browse only if intentionalstatic-deploy — Dockerfile patterns that use Caddy as the web serverdockerfile-generation — Generate the Caddyfile alongside the Dockerfiletools
Compressed catalog of all Nixopus API operations for the nixopus_api() tool
development
Deploy static file sites — Caddy/nginx serving, Staticfile config, and Dockerfile patterns. Use when deploying a static HTML site with no server-side runtime, or when index.html or a Staticfile is detected at the project root.
devops
Deploy shell script applications — interpreter detection, setup scripts, and Dockerfile patterns. Use when deploying a shell script project, or when start.sh is detected.
development
Self-healing loop for failed deployments — diagnose, fix, redeploy up to 3 attempts, then escalate or rollback. Load when a deployment fails or build errors occur.