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.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
feat(install): SERVERKIT_EXTERNAL_PROXY and SERVERKIT_CONFIG
Juan Denis4223e2ed6ac0
diff --git a/install.sh b/install.shindex ed590ddf..6f822ae3 100644--- a/install.sh+++ b/install.sh@@ -11,11 +11,62 @@# BUILD_FROM_SOURCE=1 force a source build even when a release exists# SERVERKIT_SKIP_SSL=1 run on plain HTTP (no HTTPS / no certbot attempt)#+# Running your own reverse proxy (Caddy / Traefik / nginx) in front of the panel:+#+# SERVERKIT_EXTERNAL_PROXY=1 your proxy terminates TLS; ours must not+# redirect to HTTPS. Implies SERVERKIT_SKIP_SSL=1+# and configures the trusted-proxy client IP.+# SERVERKIT_PUBLIC_URL=... the public https:// URL browsers use. Required+# with EXTERNAL_PROXY or realtime updates break.+#+# Re-runnable installs:+#+# SERVERKIT_CONFIG=/path/install.conf KEY=VALUE defaults for any of the+# variables above. Explicit environment+# still wins over the file.+## The Flask backend runs straight on the host (it needs real system access);# the React frontend is built to static files and served by the host nginx.#set -euo pipefail+# ---------------------------------------------------------------------------+# Declarative install config (SERVERKIT_CONFIG)+# ---------------------------------------------------------------------------+# Sourced before any default is applied, so a file entry behaves exactly like+# passing that variable on the command line. Runs this early — ahead of the+# terminal-styling helpers — so it can only use plain printf/exit.+load_install_config() {+ local file="${SERVERKIT_CONFIG:-}"+ [ -n "$file" ] || return 0+ if [ ! -f "$file" ]; then+ printf 'ERROR: SERVERKIT_CONFIG file not found: %s\n' "$file" >&2+ exit 1+ fi++ # The file supplies DEFAULTS. A variable already present in the environment+ # was passed explicitly for this run and must win, so apply keys one at a+ # time and skip the ones already set — sourcing the file wholesale would+ # invert that precedence. Parsing (rather than sourcing) also keeps a stray+ # command in the file from executing as root.+ local line key value+ while IFS= read -r line || [ -n "$line" ]; do+ line="${line#"${line%%[![:space:]]*}"}" # strip leading whitespace+ case "$line" in ''|'#'*) continue ;; esac+ case "$line" in 'export '*) line="${line#export }" ;; esac+ case "$line" in *=*) ;; *) continue ;; esac+ key="${line%%=*}"+ value="${line#*=}"+ # Names only; anything else is a typo, not a variable.+ case "$key" in ''|*[!A-Za-z0-9_]*) continue ;; esac+ value="${value%\"}"; value="${value#\"}"+ value="${value%\'}"; value="${value#\'}"+ [ -z "${!key+set}" ] || continue+ export "$key=$value"+ done < "$file"+}+load_install_config+# ---------------------------------------------------------------------------# Settings and environment contract# ---------------------------------------------------------------------------@@ -57,6 +108,21 @@ PROFILE_PROMPT_TIMEOUT="${SERVERKIT_PROFILE_TIMEOUT:-15}"PANEL_DOMAIN="${PANEL_DOMAIN:-}"PANEL_PORT="${PANEL_PORT:-80}"SERVERKIT_SKIP_SSL="${SERVERKIT_SKIP_SSL:-0}"++# An external reverse proxy (Caddy, Traefik, nginx elsewhere) terminates TLS in+# front of the panel and speaks plain HTTP upstream. Our own nginx must then NOT+# redirect :80 to HTTPS — the proxy would follow that redirect straight back+# into itself, which is the "too many redirects" the browser reports. So this+# implies SKIP_SSL, and it also turns on the trusted-proxy client-IP path with+# two hops (their proxy appends the client, our nginx appends their proxy).+SERVERKIT_EXTERNAL_PROXY="${SERVERKIT_EXTERNAL_PROXY:-0}"+if [ "$SERVERKIT_EXTERNAL_PROXY" = "1" ]; then+ SERVERKIT_SKIP_SSL=1+fi+# The public https:// URL browsers use. Behind a proxy the panel cannot infer+# it, and the Socket.IO handshake rejects the browser's Origin without it.+PANEL_PUBLIC_URL="${SERVERKIT_PUBLIC_URL:-}"+PANEL_PUBLIC_URL="${PANEL_PUBLIC_URL%/}"SERVERKIT_OFFLINE_TARBALL="${SERVERKIT_OFFLINE_TARBALL:-}"SERVERKIT_MIRROR_URL="${SERVERKIT_MIRROR_URL:-}"@@ -1224,6 +1290,21 @@ build_virtualenv() {# ---------------------------------------------------------------------------# Application configuration and generated secrets# ---------------------------------------------------------------------------+# Set KEY=value in an env file, replacing any existing definition (commented or+# not). Rewrites the file instead of `sed -i s|...|`: values here are URLs, and+# an unescaped '/', '&' or '|' in a sed replacement is syntax, not data.+_env_set_key() {+ local file="$1" key="$2" value="$3" tmp+ # Beside the target, not in /tmp: this file carries SECRET_KEY and the+ # encryption key, and $INSTALL_DIR is root-owned while /tmp is world-listable.+ tmp="$(mktemp "${file}.XXXXXX")"+ grep -v -E "^[[:space:]]*#?[[:space:]]*${key}=" "$file" > "$tmp" || true+ printf '%s=%s\n' "$key" "$value" >> "$tmp"+ # cat rather than mv so the original mode (0600) and owner survive.+ cat "$tmp" > "$file"+ rm -f "$tmp"+}+write_config() {phase "Configuration"@@ -1246,6 +1327,20 @@ write_config() {elseprintf 'SERVERKIT_PROFILE=%s\n' "$PROFILE" >> "$INSTALL_DIR/.env"fi+ # Converting an existing install to sit behind an external proxy is a+ # re-run with SERVERKIT_EXTERNAL_PROXY=1, and it lands here — the .env+ # already exists. Applying the switch only on a first install would make+ # the documented conversion path silently do nothing. Only ever ADD the+ # trust settings; never remove them on an ordinary re-run, which would+ # quietly break client IPs for someone who set them by hand.+ if [ "$SERVERKIT_EXTERNAL_PROXY" = "1" ]; then+ _env_set_key "$INSTALL_DIR/.env" TRUST_PROXY_HEADERS true+ _env_set_key "$INSTALL_DIR/.env" TRUSTED_PROXY_HOPS 2+ if [ -n "$PANEL_PUBLIC_URL" ]; then+ _env_set_key "$INSTALL_DIR/.env" SERVERKIT_PUBLIC_URL "$PANEL_PUBLIC_URL"+ fi+ good "External-proxy settings applied to the existing .env."+ fireturnfi@@ -1269,6 +1364,44 @@ write_config() {public_url="${url_scheme}://$PANEL_DOMAIN"fi+ # Behind someone else's proxy the browser's origin is the proxy's https URL,+ # which no local signal reveals — SSL_MODE is 'insecure' here precisely+ # because *we* do not terminate TLS. So the operator-supplied value wins,+ # and it must be live (not commented out) or every websocket handshake 400s.+ local proxy_block=""+ if [ -n "$PANEL_PUBLIC_URL" ]; then+ public_url="$PANEL_PUBLIC_URL"+ case ",$cors_origins," in+ *",$public_url,"*) ;;+ *) cors_origins="$cors_origins,$public_url" ;;+ esac+ fi+ # Derived-from-the-domain URLs stay commented (they are a guess, and a wrong+ # SERVERKIT_PUBLIC_URL breaks websockets rather than merely not helping).+ # An operator-supplied one is written live.+ local public_url_line=""+ if [ -n "$PANEL_PUBLIC_URL" ]; then+ public_url_line="SERVERKIT_PUBLIC_URL=$public_url"+ elif [ -n "$public_url" ]; then+ public_url_line="# SERVERKIT_PUBLIC_URL=$public_url"+ fi++ if [ "$SERVERKIT_EXTERNAL_PROXY" = "1" ]; then+ # Two hops: their proxy appends the real client, our nginx appends their+ # proxy. ProxyFix counts from the right, so 1 would log their proxy's IP+ # for every request and 3 would let a client forge its own.+ proxy_block=$(cat <<'PROXYEOF'++# Trusted reverse proxy — set because this install sits behind an external+# TLS-terminating proxy (SERVERKIT_EXTERNAL_PROXY=1). Derives the real client+# IP from X-Forwarded-For for rate limits, login lockout and audit logs.+# TRUSTED_PROXY_HOPS = proxies in front of Flask: external proxy + our nginx.+TRUST_PROXY_HEADERS=true+TRUSTED_PROXY_HOPS=2+PROXYEOF+)+ fi+cat > "$INSTALL_DIR/.env" <<EOF# ServerKit Configuration# Generated on $(date)@@ -1284,13 +1417,16 @@ DATABASE_URL=sqlite:///$INSTALL_DIR/backend/instance/serverkit.db# CORS Origins (comma-separated, add your domain)CORS_ORIGINS=$cors_origins-# Public URL for agents and install commands (optional)-${public_url:+# SERVERKIT_PUBLIC_URL=$public_url}+# Public URL for agents, browsers and install commands. Behind a reverse proxy+# this must be the URL users actually browse to, or the websocket handshake is+# rejected on origin and the UI stops live-updating.+$public_url_line# SSL mode (secure|insecure) — gates the panel's HSTS header so HTTPS stays# optional. Mirrors /etc/serverkit/ssl-mode; set to 'secure' only when this# server terminates real end-to-end HTTPS.SERVERKIT_SSL_MODE=$SSL_MODE+$proxy_block# Install profile (minimal|standard|full) — what this install provisioned, not# a licence tier. The panel reads it to decide whether to offer app hosting;@@ -2291,6 +2427,40 @@ prompt_for_domain() {fi}+prompt_for_public_url() {+ # Only meaningful when someone else terminates TLS in front of us.+ [ "$SERVERKIT_EXTERNAL_PROXY" = "1" ] || return 0+ [ -z "$PANEL_PUBLIC_URL" ] || return 0++ # Derive rather than ask when the domain already answers the question.+ if [ -n "$PANEL_DOMAIN" ]; then+ PANEL_PUBLIC_URL="https://$PANEL_DOMAIN"+ good "Public URL: $PANEL_PUBLIC_URL (from PANEL_DOMAIN)"+ return 0+ fi++ if [ ! -t 0 ] && [ "${SERVERKIT_FORCE_PROMPT:-0}" != "1" ]; then+ warn "SERVERKIT_EXTERNAL_PROXY=1 without SERVERKIT_PUBLIC_URL."+ warn "Realtime updates will be rejected until you set it in $INSTALL_DIR/.env."+ return 0+ fi++ printf '\n'+ printf '%sPublic URL of the panel, as your reverse proxy publishes it%s\n' "$BLD" "$RST"+ printf 'Example: https://serverkit.example.com\n'+ printf 'Required: the browser sends this as its websocket Origin, and the\n'+ printf 'panel rejects the handshake when it does not match.\n'+ printf '%sTip:%s set SERVERKIT_PUBLIC_URL=... to skip this prompt\n' "$BLD" "$RST"+ printf '> '+ read -r PANEL_PUBLIC_URL || true+ PANEL_PUBLIC_URL=$(printf '%s' "$PANEL_PUBLIC_URL" | tr -d ' ')+ PANEL_PUBLIC_URL="${PANEL_PUBLIC_URL%/}"+ if [ -z "$PANEL_PUBLIC_URL" ]; then+ warn "No public URL given — realtime updates will be rejected until"+ warn "SERVERKIT_PUBLIC_URL is set in $INSTALL_DIR/.env."+ fi+}+# ---------------------------------------------------------------------------# Orchestration# ---------------------------------------------------------------------------@@ -2330,6 +2500,7 @@ main() {# whether provision_docker runs at all.prompt_for_profileprompt_for_domain+ prompt_for_public_urlsnapshot_existing# RHEL 9 family: keep sshd alive across the dnf work below (see thediff --git a/scripts/test/test_install.sh b/scripts/test/test_install.shindex b93da492..209fa2e6 100644--- a/scripts/test/test_install.sh+++ b/scripts/test/test_install.sh@@ -318,22 +318,68 @@ elsefi# ---------------------------------------------------------------------------# T12 — the canonical docker-compose.yml is frontend-only. The backend manages-# the host (creates /var/serverkit/apps/*, drives host Docker, reloads nginx),-# which a container cannot do — a backend container fails app creation with-# `Permission denied: /var/serverkit/apps/...` and has no host docker.sock.-# Guard against re-adding a `backend` compose service (the regression that-# broke WordPress/app creation).+# T12 — docker-compose.yml shape.+#+# Two separate contracts live in this one file, and both have already been+# broken once:+#+# 1. No `backend:` service. On a HOST install the backend manages the host+# (creates /var/serverkit/apps/*, drives host Docker, reloads nginx),+# which a container cannot do — a backend container fails app creation+# with `Permission denied: /var/serverkit/apps/...` and has no host+# docker.sock. This broke WordPress/app creation once already.+# 2. Plain `docker compose up -d` must start something. Every service was+# once behind the `legacy-frontend` profile, so the default command+# started NOTHING while the README still told people to run it — issue+# #96, where the reporter ran the profile by hand and got an nginx+# container serving an empty dist directory (403).# --------------------------------------------------------------------------compose="$REPO_DIR/docker-compose.yml"+# Service keys inside the `services:` block that carry no `profiles:` — i.e.+# exactly what a plain `docker compose up -d` would start. Literal spaces+# rather than {2}/{4} intervals so this works on any awk.+compose_default_services="$(awk '+ /^services:/ { in_services = 1; next }+ /^[a-zA-Z]/ { in_services = 0 }+ !in_services { next }+ /^ [a-zA-Z0-9_-]+:[ ]*$/ { svc = $1; sub(/:$/, "", svc); order[++n] = svc; cur = svc; next }+ /^ profiles:/ { if (cur != "") profiled[cur] = 1 }+ END { for (i = 1; i <= n; i++) if (!profiled[order[i]]) print order[i] }+' "$compose" | sort | tr '\n' ' ')"+if grep -Eq '^[[:space:]]{2}backend:' "$compose"; thenbad "docker-compose.yml defines a 'backend' service — the backend must run on the host, not in a container"elif ! grep -Eq '^[[:space:]]{2}frontend:' "$compose"; then- bad "docker-compose.yml is missing the 'frontend' service"+ bad "docker-compose.yml is missing the legacy 'frontend' service"elif ! grep -q 'backend:host-gateway' "$compose"; thenbad "docker-compose.yml frontend is missing the 'backend:host-gateway' alias to reach the host backend"+elif ! awk '/^ frontend:/{f=1} f&&/^ profiles:/{print;exit}' "$compose" | grep -q 'legacy-frontend'; then+ bad "the legacy frontend service is no longer behind the 'legacy-frontend' profile"+else+ ok "docker-compose.yml has no backend service and keeps the legacy frontend profiled"+fi++# `docker compose up -d` must resolve to at least one service. Anything without+# a `profiles:` key starts by default.+if [ -z "${compose_default_services// /}" ]; then+ bad "every docker-compose.yml service is behind a profile — 'docker compose up -d' would start NOTHING (issue #96)"+elif ! grep -Eq '^[[:space:]]{2}serverkit:' "$compose"; then+ bad "docker-compose.yml no longer defines the all-in-one 'serverkit' service"+else+ ok "'docker compose up -d' starts the all-in-one panel [$compose_default_services]"+fi++# The all-in-one image writes its SQLite database to /app/instance. The+# Dockerfile must create that directory and chown it to the non-root runtime+# user, or the container dies on boot with "unable to open database file" —+# and a named volume mounted there inherits root ownership (issue #96).+dockerfile="$REPO_DIR/Dockerfile"+if ! grep -q '/app/instance' "$dockerfile"; then+ bad "Dockerfile never creates /app/instance — the container cannot open its database"+elif ! grep -Eq 'mkdir -p .*/app/instance' "$dockerfile"; then+ bad "Dockerfile mentions /app/instance but does not mkdir it"else- ok "docker-compose.yml is frontend-only and routes /api to the host backend (backend:host-gateway)"+ ok "Dockerfile creates /app/instance for the database volume"fi# --------------------------------------------------------------------------@@ -1818,6 +1864,197 @@ elsebad "bootstrap_firewall no longer detects the SSH port — LOCKOUT RISK"fi+# --------------------------------------------------------------------------+# T43 — plan 71: running behind an operator's own reverse proxy.+#+# Issue #96. Two switches, and the failure modes are silent ones: a panel that+# still 301s to HTTPS traps the proxy in a redirect loop, and a missing+# SERVERKIT_PUBLIC_URL leaves the UI loading but never live-updating because+# every websocket handshake is rejected on origin.+# --------------------------------------------------------------------------+printf '\nT43 — external reverse proxy (SERVERKIT_EXTERNAL_PROXY / SERVERKIT_CONFIG)\n'+t43="$WORK/t43"+mkdir -p "$t43"++# -- EXTERNAL_PROXY implies SKIP_SSL. Sourcing install.sh re-runs the settings+# block, so the implication is observable without running an install.+out="$( set -Eeuo pipefail+ SERVERKIT_EXTERNAL_PROXY=1+ unset SERVERKIT_SKIP_SSL || true+ source "$INSTALL_SH" >/dev/null 2>&1+ printf '%s' "$SERVERKIT_SKIP_SSL" )"+if [ "$out" = "1" ]; then+ ok "SERVERKIT_EXTERNAL_PROXY=1 implies SERVERKIT_SKIP_SSL=1 (no HTTPS redirect to loop on)"+else+ bad "SERVERKIT_EXTERNAL_PROXY=1 left SERVERKIT_SKIP_SSL=[$out] — the panel would still 301 to HTTPS"+fi++# -- and it must NOT flip SKIP_SSL for an ordinary install.+out="$( set -Eeuo pipefail+ unset SERVERKIT_EXTERNAL_PROXY SERVERKIT_SKIP_SSL || true+ source "$INSTALL_SH" >/dev/null 2>&1+ printf '%s' "$SERVERKIT_SKIP_SSL" )"+if [ "$out" = "0" ]; then+ ok "the default install is untouched (SERVERKIT_SKIP_SSL=0)"+else+ bad "an ordinary install now skips SSL (SERVERKIT_SKIP_SSL=[$out])"+fi++# -- a trailing slash on the public URL must be stripped: a browser's Origin+# header never carries one, so storing it raw would never match.+out="$( set -Eeuo pipefail+ SERVERKIT_EXTERNAL_PROXY=1+ SERVERKIT_PUBLIC_URL="https://panel.example.com/"+ source "$INSTALL_SH" >/dev/null 2>&1+ printf '%s' "$PANEL_PUBLIC_URL" )"+if [ "$out" = "https://panel.example.com" ]; then+ ok "a trailing slash is stripped from SERVERKIT_PUBLIC_URL"+else+ bad "SERVERKIT_PUBLIC_URL normalised to [$out]"+fi++# -- SERVERKIT_CONFIG supplies defaults...+cat > "$t43/install.conf" <<'CONF'+# ServerKit install config+SERVERKIT_EXTERNAL_PROXY=1+SERVERKIT_PUBLIC_URL="https://from-file.example.com"+SERVERKIT_PROFILE=minimal+CONF+out="$( set -Eeuo pipefail+ unset SERVERKIT_EXTERNAL_PROXY SERVERKIT_PUBLIC_URL SERVERKIT_PROFILE || true+ SERVERKIT_CONFIG="$t43/install.conf"+ source "$INSTALL_SH" >/dev/null 2>&1+ printf '%s|%s|%s' "$SERVERKIT_EXTERNAL_PROXY" "$PANEL_PUBLIC_URL" "$PROFILE" )"+if [ "$out" = "1|https://from-file.example.com|minimal" ]; then+ ok "SERVERKIT_CONFIG supplies defaults (quotes stripped, comments ignored)"+else+ bad "SERVERKIT_CONFIG produced [$out]"+fi++# -- ...but explicit environment always wins over the file.+out="$( set -Eeuo pipefail+ unset SERVERKIT_EXTERNAL_PROXY || true+ SERVERKIT_CONFIG="$t43/install.conf"+ SERVERKIT_PUBLIC_URL="https://from-env.example.com"+ SERVERKIT_PROFILE=full+ source "$INSTALL_SH" >/dev/null 2>&1+ printf '%s|%s' "$PANEL_PUBLIC_URL" "$PROFILE" )"+if [ "$out" = "https://from-env.example.com|full" ]; then+ ok "explicit environment overrides SERVERKIT_CONFIG"+else+ bad "SERVERKIT_CONFIG overrode the explicit environment: [$out]"+fi++# -- a missing config file is a hard error, not a silently-default install.+if ( set -Eeuo pipefail+ SERVERKIT_CONFIG="$t43/nope.conf"+ source "$INSTALL_SH" >/dev/null 2>&1 ) ; then+ bad "a missing SERVERKIT_CONFIG file was ignored"+else+ ok "a missing SERVERKIT_CONFIG file aborts instead of installing the wrong shape"+fi++# -- the file must be parsed, not executed: a command in it must not run.+printf 'touch %s/pwned\nSERVERKIT_PROFILE=minimal\n' "$t43" > "$t43/evil.conf"+( set -Eeuo pipefail+ unset SERVERKIT_PROFILE || true+ SERVERKIT_CONFIG="$t43/evil.conf"+ source "$INSTALL_SH" >/dev/null 2>&1 ) || true+if [ -e "$t43/pwned" ]; then+ bad "SERVERKIT_CONFIG executed a command from the file — it must be parsed, not sourced"+else+ ok "SERVERKIT_CONFIG is parsed, not sourced (a stray command does not run as root)"+fi++# -- write_config on an EXISTING .env must apply the proxy settings, because+# "convert my install to sit behind Caddy" is a re-run and lands there.+env_dir="$t43/opt"+mkdir -p "$env_dir"+cat > "$env_dir/.env" <<'ENVEOF'+SECRET_KEY=keep-me+SERVERKIT_SSL_MODE=secure+# TRUST_PROXY_HEADERS=false+ENVEOF+( set -Eeuo pipefail+ source "$INSTALL_SH" >/dev/null 2>&1+ INSTALL_DIR="$env_dir"; SSL_MODE=insecure; PROFILE=standard+ SERVERKIT_EXTERNAL_PROXY=1; PANEL_PUBLIC_URL="https://panel.example.com"+ write_config >/dev/null 2>&1 )+if grep -q '^TRUST_PROXY_HEADERS=true' "$env_dir/.env" \+ && grep -q '^TRUSTED_PROXY_HOPS=2' "$env_dir/.env" \+ && grep -q '^SERVERKIT_PUBLIC_URL=https://panel.example.com$' "$env_dir/.env" \+ && grep -q '^SECRET_KEY=keep-me' "$env_dir/.env" \+ && [ "$(grep -c 'TRUST_PROXY_HEADERS' "$env_dir/.env")" = "1" ]; then+ ok "converting an existing install rewrites the proxy keys and keeps the secrets"+else+ bad "existing-.env conversion produced: [$(tr '\n' ' ' < "$env_dir/.env")]"+fi++# -- and SERVERKIT_SSL_MODE must flip to insecure in the .env, not only in+# /etc/serverkit/ssl-mode. _resolve_ssl_mode() reads the ENV VAR FIRST and+# only falls back to the file, and run.py load_dotenv()s this file — so a+# stale SERVERKIT_SSL_MODE=secure here keeps HSTS on and tells browsers to+# force HTTPS on a port that now only speaks plain HTTP.+if grep -q '^SERVERKIT_SSL_MODE=insecure' "$env_dir/.env" \+ && ! grep -q '^SERVERKIT_SSL_MODE=secure' "$env_dir/.env"; then+ ok "the converted .env records ssl-mode=insecure so HSTS stops being sent"+else+ bad "SERVERKIT_SSL_MODE was not flipped to insecure: [$(grep SERVERKIT_SSL_MODE "$env_dir/.env" | tr '\n' ' ')]"+fi++# -- an ordinary re-run must not strip proxy settings someone configured by hand.+( set -Eeuo pipefail+ source "$INSTALL_SH" >/dev/null 2>&1+ INSTALL_DIR="$env_dir"; SSL_MODE=insecure; PROFILE=standard+ SERVERKIT_EXTERNAL_PROXY=0+ write_config >/dev/null 2>&1 )+if grep -q '^TRUST_PROXY_HEADERS=true' "$env_dir/.env"; then+ ok "a plain re-run leaves existing proxy settings alone"+else+ bad "a plain re-run removed TRUST_PROXY_HEADERS from an existing .env"+fi++# -- only ONE default server may exist on :80.+#+# Both site configs declare `listen 80 default_server` and then include+# /etc/nginx/serverkit-conf.d/*.conf. install.sh writes the canonical-domain+# redirect into that directory whenever PANEL_DOMAIN is set, and it used to+# declare `listen 80 default_server` as well — which nginx rejects outright+# ("a duplicate default server for 0.0.0.0:80"), in BOTH ssl modes. Since+# launch_services starts nginx after write_config, every first install with a+# domain produced an nginx that would not start. Verified against real nginx.+# Directives only — the block's own comments explain this trap by naming it.+canon_block="$(awk '/canonical-domain.conf <<EOF/,/^EOF$/' "$INSTALL_SH" \+ | grep -v '^[[:space:]]*#')"+if [ -z "$canon_block" ]; then+ bad "could not find the canonical-domain.conf heredoc in install.sh"+elif printf '%s' "$canon_block" | grep -q 'default_server'; then+ bad "the canonical-domain redirect declares default_server — nginx will refuse to start on any PANEL_DOMAIN install"+elif ! printf '%s' "$canon_block" | grep -q 'server_name ~'; then+ bad "the canonical-domain redirect no longer matches a bare IP by regex server_name — the redirect will never fire"+else+ ok "the canonical-domain redirect matches a bare IP without a second default_server"+fi++# -- and the shipped sites must remain the ONLY default server on :80.+for site in serverkit.conf serverkit-insecure.conf; do+ n="$(grep -c 'listen 80 default_server' "$REPO_DIR/nginx/sites-available/$site" || true)"+ if [ "$n" = "1" ]; then+ ok "$site declares exactly one default server on :80"+ else+ bad "$site declares $n default servers on :80 (expected 1)"+ fi+done++# -- static guard: the documented insecure site must keep shipping, since both+# the docs and SERVERKIT_EXTERNAL_PROXY point operators straight at it.+if [ -f "$REPO_DIR/nginx/sites-available/serverkit-insecure.conf" ] \+ && ! grep -qE 'return[[:space:]]+30[12]' "$REPO_DIR/nginx/sites-available/serverkit-insecure.conf"; then+ ok "serverkit-insecure.conf ships and contains no redirect for a proxy to loop on"+else+ bad "serverkit-insecure.conf is missing or now redirects — issue #96 would recur"+fi+# --------------------------------------------------------------------------printf '\n%d passed, %d failed, %d skipped\n\n' "$PASS" "$FAIL" "$SKIP"[ "$FAIL" -eq 0 ]