Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

fix(nginx): never-cache the SPA entrypoint; warn on stale :3847 panel vhosts

Juan Denis4af3df113684
diff --git a/nginx/sites-available/serverkit-insecure.conf b/nginx/sites-available/serverkit-insecure.conf
index a5a2bad9..eba294ed 100644
--- a/nginx/sites-available/serverkit-insecure.conf
+++ b/nginx/sites-available/serverkit-insecure.conf
@@ -40,6 +40,10 @@ server {
}
location / {
+ # expires -1 → Cache-Control: no-cache — the entrypoint must
+ # revalidate every load or a cached index.html references hashed
+ # assets deleted by the next blue/green switch.
+ expires -1;
try_files $uri $uri/ /index.html;
}
diff --git a/nginx/sites-available/serverkit.conf b/nginx/sites-available/serverkit.conf
index f5c0312a..9cc0e2de 100644
--- a/nginx/sites-available/serverkit.conf
+++ b/nginx/sites-available/serverkit.conf
@@ -121,6 +121,11 @@ server {
}
location / {
+ # expires -1 (not add_header): emits Cache-Control: no-cache without
+ # discarding the server-level security headers, and forces every load
+ # to revalidate the entrypoint — a cached index.html references hashed
+ # assets that no longer exist after the next blue/green switch.
+ expires -1;
try_files $uri $uri/ /index.html;
}
diff --git a/scripts/test/test_update.sh b/scripts/test/test_update.sh
index eb8d4a58..62f87f31 100644
--- a/scripts/test/test_update.sh
+++ b/scripts/test/test_update.sh
@@ -386,8 +386,43 @@ for f in serverkit.conf serverkit-insecure.conf; do
else
bad "$f is not a clean static-serve config (still proxying :3847?)"
fi
+ # The HTML entrypoint must revalidate every load (expires -1 → no-cache):
+ # a cached index.html references hashed assets that vanish on the next
+ # blue/green switch, bricking the panel behind any caching layer.
+ if grep -q 'expires -1;' "$cfg"; then
+ ok "$f marks the SPA entrypoint no-cache (expires -1)"
+ else
+ bad "$f lets the HTML entrypoint be cached — stale index.html breaks after a slot switch"
+ fi
done
+# --------------------------------------------------------------------------
+# T15b — report_stale_panel_vhosts: a leftover custom vhost proxying the
+# retired :3847 frontend container serves a permanently stale panel bundle
+# (2026-07-03 incident: looked exactly like a browser/CDN cache problem).
+# The check must WARN and name the file — and never abort, even with no
+# sites-enabled dir at all (fresh box; also covered by the loop below).
+# --------------------------------------------------------------------------
+t="$WORK/t15b"; mkdir -p "$t/nginx/sites-enabled"
+printf 'server {\n location / {\n proxy_pass http://127.0.0.1:3847;\n }\n}\n' \
+ > "$t/nginx/sites-enabled/legacy-panel.conf"
+printf 'server {\n root /opt/serverkit/frontend/dist;\n}\n' \
+ > "$t/nginx/sites-enabled/clean.conf"
+if out="$( set -Eeuo pipefail; NGINX_DIR="$t/nginx"; INSTALL_DIR="/opt/serverkit"
+ report_stale_panel_vhosts 2>&1 )" \
+ && printf '%s' "$out" | grep -q 'legacy-panel.conf' \
+ && ! printf '%s' "$out" | grep -q 'clean.conf'; then
+ ok "report_stale_panel_vhosts warns about (only) vhosts proxying :3847"
+else
+ bad "report_stale_panel_vhosts missed the stale vhost or flagged a clean one: [$out]"
+fi
+if out="$( set -Eeuo pipefail; NGINX_DIR="$t/nowhere"; INSTALL_DIR="/opt/serverkit"
+ report_stale_panel_vhosts 2>&1 )" && [ -z "$out" ]; then
+ ok "report_stale_panel_vhosts is silent (rc 0) with no sites-enabled dir"
+else
+ bad "report_stale_panel_vhosts failed or spoke on a missing dir: [$out]"
+fi
+
# --------------------------------------------------------------------------
# T16 — app-uptime verification: discover_app_upstreams must extract the unique
# set of app container upstreams from the per-app nginx location snippets (this
@@ -761,7 +796,7 @@ UPDATE_OBSERVERS=(
version_gate active_real_dir next_real_dir discover_app_upstreams
probe_app_upstreams snapshot_app_reachability report_app_uptime_regressions
locate_python wait_for_service quick_health is_docker_deployment
- snapshot_docker_state report_failure
+ snapshot_docker_state report_failure report_stale_panel_vhosts
)
loop_fail=0
diff --git a/scripts/update.sh b/scripts/update.sh
index fcf9f749..99f19d26 100644
--- a/scripts/update.sh
+++ b/scripts/update.sh
@@ -1013,9 +1013,29 @@ EOF
fi
systemctl daemon-reload 2>/dev/null \
|| warn "systemd daemon-reload failed — the backend may restart with a stale unit"
+
+ report_stale_panel_vhosts
good "Configuration refreshed"
}
+# The panel used to be served by a frontend container on :3847; it is now
+# served statically by host nginx. A leftover custom vhost proxying to :3847
+# keeps serving whatever bundle the (never-updated) container holds — the
+# panel looks "stuck on an old version" for that hostname only, which reads
+# like a browser/CDN cache problem and wastes hours (2026-07-03 incident).
+# Observation only (R1): warn and continue, tolerate a missing/empty dir.
+report_stale_panel_vhosts() {
+ local hits=""
+ hits="$(grep -rls 'proxy_pass http://127\.0\.0\.1:3847' \
+ "$NGINX_DIR/sites-enabled/" 2>/dev/null | sort -u | tr '\n' ' ' || true)"
+ if [ -n "$hits" ]; then
+ warn "Vhost(s) still proxy the panel to the retired :3847 frontend container: ${hits}"
+ warn " These serve a STALE panel bundle. Repoint them at the static SPA"
+ warn " (root $INSTALL_DIR/frontend/dist + /api and /socket.io → :5000),"
+ warn " mirroring sites-available/serverkit.conf."
+ fi
+}
+
# ---------------------------------------------------------------------------
# Rollback
# ---------------------------------------------------------------------------