Two paths are supported: Cloudflare Pages (the live deployment) and a
Docker container for self-hosting. Both serve the same static dist/.
The repository is connected to a Pages project; a push to main triggers a build.
| Setting | Value |
|---|---|
| Framework preset | Astro |
| Build command | pnpm build |
| Build output directory | dist |
| Environment variable | NODE_VERSION=22 (or .nvmrc) |
| Environment variable | SITE_URL=https://java-guru.pages.dev (or your domain) |
pnpm build runs Astro and then Pagefind, so the search index ships with the
deployment. public/_redirects is copied into dist; Cloudflare applies those
rules before serving, which is how legacy single-language URLs keep working:
/posts/:splat → /en/posts/:splat 301
/categories/:splat → /en/categories/:splat 301
/about → /en/about/ 301
/rss.xml → /en/rss.xml 301
Preview deployments get their own *.pages.dev hostname; canonical URLs follow
SITE_URL, so set it per environment if you want previews to self-canonicalize.
Cache behaviour is Cloudflare's default for static assets plus the _headers
values baked into the HTML (assets are content-hashed, HTML revalidates).
The site is a fully static build: HTML, CSS, a little JS, self-hosted fonts, local images and a Pagefind index. There is no database, no server runtime and no secrets baked into the image.
Two layers are involved, and this project only owns the second one:
- Host reverse proxy — already running on the VPS (Caddy, Nginx, Traefik…).
It owns
:80/:443, certificates and DNS. - java-guru container — Caddy serving
dist/on:8080, published to127.0.0.1:8080by default.
Nothing in this repository changes firewall rules, SSH configuration, DNS, or the configuration of any service already running on the host.
| Requirement | Notes |
|---|---|
| Docker Engine ≥ 24 | docker --version |
| Docker Compose v2 plugin | docker compose version |
| ~1.5 GB free disk | Build cache + image (~180 MB) |
| Node 20.19+ | Only if you build outside Docker |
git clone https://github.com/hungpt99-dev/java-guru.git
cd java-guru
cp .env.example .env
# edit .env: SITE_URL must be the public origin users will visit
docker compose up -d --build
docker compose ps # wait for "healthy"
curl -I http://127.0.0.1:8080/ # 200SITE_URL is a build argument: it is baked into canonical URLs, the sitemap,
RSS links and JSON-LD. Changing the domain requires a rebuild
(docker compose up -d --build), not a restart.
| Variable | Default | Scope | Purpose |
|---|---|---|---|
SITE_URL |
https://java-guru.dev |
build | Public origin for canonical URLs, sitemap, RSS, structured data |
BIND_ADDR |
127.0.0.1 |
runtime | Host interface the container publishes on |
PORT |
8080 |
runtime | Host port mapped to the container's :8080 |
There are no runtime secrets. Do not add .env to git (it is ignored).
If the host already runs Caddy, add one block and reload:
java-guru.dev {
encode zstd gzip
reverse_proxy 127.0.0.1:8080
}sudo caddy validate --config /etc/caddy/Caddyfile
sudo systemctl reload caddyCaddy obtains and renews the certificate automatically once DNS points at the VPS.
server {
listen 80;
server_name java-guru.dev;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
http2 on;
server_name java-guru.dev;
ssl_certificate /etc/letsencrypt/live/java-guru.dev/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/java-guru.dev/privkey.pem;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}sudo certbot --nginx -d java-guru.devOnly when nothing else on the host binds :80 / :443:
- In
deploy/Caddyfile, removeauto_https offand replace:8080 {withjava-guru.dev {. - Set
BIND_ADDR=0.0.0.0and map80:8080/443:8443in compose. - Caddy will provision certificates itself (requires ports 80 and 443 open).
Do not open ports that your existing firewall deliberately keeps closed; the host reverse proxy is the safer default.
git pull
docker compose up -d --build
docker compose psAssets are content-hashed, so browsers pick up new CSS/JS immediately while old
hashed files stay cacheable. HTML is served with must-revalidate.
docker tag java-guru:latest java-guru:rollback # before deploying a change
docker compose up -d --build # deploy
# if something is wrong:
docker tag java-guru:rollback java-guru:latest && docker compose up -dThe image ships a HEALTHCHECK hitting /healthz (returns ok), and compose
declares the same probe. A failing container is restarted by
restart: unless-stopped policy only if it exits; a hung-but-listening process
is visible via docker compose ps as unhealthy.
curl -sI https://java-guru.dev/ # 200, cache headers
curl -s https://java-guru.dev/robots.txt # Sitemap: .../sitemap-index.xml
curl -s https://java-guru.dev/rss.xml | head # valid RSS
curl -s https://java-guru.dev/sitemap-index.xml | head
curl -s https://java-guru.dev/en/posts/ | grep -c 'post-row' # English listing
curl -s https://java-guru.dev/vi/posts/ | grep -c 'post-row' # Vietnamese listing
curl -sI https://java-guru.dev/posts/hieu-saga-pattern-trong-5-phut/ | head -1 # 301 → /en/…Search only works in a production build: pnpm build runs Pagefind and writes
dist/pagefind/. In pnpm dev the search UI shows a hint instead of results.
| Symptom | Cause / fix |
|---|---|
permission denied writing /config |
Root filesystem is read-only; compose provides tmpfs mounts. Keep them. |
| Legacy URL returns 200 instead of 301 | public/_redirects is only applied by Cloudflare Pages; for Docker the same rules live in deploy/Caddyfile. |
404 on /en/posts/foo but /en/posts/foo/ works |
The proxy is stripping the trailing slash; use reverse_proxy (Option A/B) rather than hand-written rewrite rules. |
| Old content after deploy | Browser/CDN cache on HTML — HTML is max-age=0, must-revalidate; purge the CDN if one sits in front. |
| Search returns nothing | dist/pagefind/ missing: the image build must run pnpm build, not astro build alone. |
| Container restarts every few seconds | Usually a Caddyfile syntax error: docker compose logs web. |
The runtime image is Caddy + static files: ~40 MB RAM at idle, no CPU between requests, no persistent volumes.