Private
Public Access
Make the reverse proxy a required, pluggable part of every deployment
gunicorn previously only ever bound to a Unix socket, which assumes the reverse proxy is nginx running on this same host — it can't be reached by a proxy on a different machine at all (e.g. Nginx Proxy Manager on its own box), which is this project's actual deployment target. Switch gunicorn to listening on a plain TCP address instead, controlled by a new EVECTION_GUNICORN_BIND setting in .env. install.sh now asks whether the proxy is local or remote and picks a sensible bind default either way (127.0.0.1:8000 vs 0.0.0.0:8000, with a reminder to firewall the port in the remote case), and no longer tries to automate nginx/certbot itself — docs/install.md's new "Reverse proxy" section covers both shapes instead, since which proxy and where it runs is the operator's choice, not something this script should assume or set up. upgrade.sh's health check now curls the TCP bind instead of the old socket path. Also add WhiteNoise so gunicorn serves /static/ itself: the old approach (nginx aliasing the staticfiles directory on disk) silently breaks the moment the proxy isn't on this host and can't see this filesystem. nginx.conf.example's own /static/ alias becomes an optional same-host perf optimization rather than a requirement. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
62702e13e3
commit
21c33e8188
7 files changed
+157
-91
No files matched your search
+38
-51
@@ -1,6 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
# Automates docs/install.md's manual steps: system user, virtualenv, .env,
|
||||
# migrate/collectstatic, systemd units, and (optionally) nginx + TLS.
|
||||
# migrate/collectstatic, systemd units. Does NOT set up a reverse proxy —
|
||||
# Evection always requires one in front of gunicorn (see docs/install.md),
|
||||
# but which one (local nginx/Caddy/Traefik, or something like Nginx Proxy
|
||||
# Manager on a different host entirely) is up to you, so this script just
|
||||
# leaves gunicorn listening on EVECTION_GUNICORN_BIND for you to point it
|
||||
# at.
|
||||
#
|
||||
# Run as root, from inside the checkout you want to serve:
|
||||
# sudo ./scripts/install.sh
|
||||
@@ -11,7 +16,7 @@
|
||||
# Non-interactive use (e.g. scripted provisioning) — set these before
|
||||
# running, and the script won't prompt:
|
||||
# EVECTION_ALLOWED_HOSTS, EVECTION_DATABASE_URL, EVECTION_REDIS_URL,
|
||||
# EVECTION_USER (defaults to "evection")
|
||||
# EVECTION_GUNICORN_BIND, EVECTION_USER (defaults to "evection")
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
@@ -58,12 +63,10 @@ if ! "$PYTHON_BIN" -c 'import ensurepip' >/dev/null 2>&1; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for bin in redis-cli nginx; do
|
||||
if ! command -v "$bin" >/dev/null 2>&1; then
|
||||
echo "Warning: '$bin' not found on PATH. Install it before going live" \
|
||||
"(see docs/install.md's prerequisites section: apt install redis-server nginx)." >&2
|
||||
fi
|
||||
done
|
||||
if ! command -v redis-cli >/dev/null 2>&1; then
|
||||
echo "Warning: 'redis-cli' not found on PATH. Install it before going live" \
|
||||
"(see docs/install.md's prerequisites section: apt install redis-server)." >&2
|
||||
fi
|
||||
|
||||
# --- 2. System user -----------------------------------------------------
|
||||
|
||||
@@ -138,12 +141,31 @@ if [ ! -f "$ENV_FILE" ]; then
|
||||
fi
|
||||
DATABASE_URL="${DATABASE_URL:-sqlite:///$APP_DIR/db.sqlite3}"
|
||||
|
||||
GUNICORN_BIND="${EVECTION_GUNICORN_BIND:-}"
|
||||
if [ -z "$GUNICORN_BIND" ] && [ -t 0 ]; then
|
||||
echo
|
||||
echo "Evection must run behind a reverse proxy — gunicorn needs an" \
|
||||
"address:port that proxy can reach."
|
||||
read -rp "Is the reverse proxy on this same machine, or a different one? [same/different] [same]: " PROXY_LOCATION
|
||||
if [[ "${PROXY_LOCATION:-}" =~ ^[Dd] ]]; then
|
||||
read -rp "Address:port for gunicorn to listen on (e.g. 0.0.0.0:8000, or this host's own IP:8000) [0.0.0.0:8000]: " GUNICORN_BIND
|
||||
GUNICORN_BIND="${GUNICORN_BIND:-0.0.0.0:8000}"
|
||||
echo " Remember to firewall this port to only accept connections" \
|
||||
"from the reverse proxy's host."
|
||||
else
|
||||
read -rp "Address:port for gunicorn to listen on [127.0.0.1:8000]: " GUNICORN_BIND
|
||||
GUNICORN_BIND="${GUNICORN_BIND:-127.0.0.1:8000}"
|
||||
fi
|
||||
fi
|
||||
GUNICORN_BIND="${GUNICORN_BIND:-127.0.0.1:8000}"
|
||||
|
||||
cat > "$ENV_FILE" <<EOF
|
||||
SECRET_KEY=$SECRET_KEY
|
||||
DEBUG=False
|
||||
ALLOWED_HOSTS=$ALLOWED_HOSTS
|
||||
DATABASE_URL=$DATABASE_URL
|
||||
REDIS_URL=${EVECTION_REDIS_URL:-redis://localhost:6379/0}
|
||||
EVECTION_GUNICORN_BIND=$GUNICORN_BIND
|
||||
EVECTION_SIGNUP_ENABLED=False
|
||||
EVECTION_MIN_FETCH_INTERVAL_MINUTES=15
|
||||
EVECTION_PWA_CACHE_VERSION=v1
|
||||
@@ -154,6 +176,11 @@ else
|
||||
echo "==> $ENV_FILE already exists — leaving it alone"
|
||||
fi
|
||||
|
||||
# Needed below for the final "gunicorn is listening on..." message even
|
||||
# when $ENV_FILE already existed and the block above was skipped.
|
||||
GUNICORN_BIND="$(grep -m1 '^EVECTION_GUNICORN_BIND=' "$ENV_FILE" | cut -d= -f2-)"
|
||||
GUNICORN_BIND="${GUNICORN_BIND:-127.0.0.1:8000}"
|
||||
|
||||
# --- 5. Migrate + static files --------------------------------------------
|
||||
|
||||
echo "==> Running migrations"
|
||||
@@ -181,49 +208,9 @@ echo "==> Services installed. Checking status..."
|
||||
systemctl --no-pager status evection-gunicorn evection-celery-worker evection-celery-beat \
|
||||
|| echo "One or more services didn't start cleanly — see 'journalctl -u evection-gunicorn' etc." >&2
|
||||
|
||||
# --- 7. nginx (optional) ---------------------------------------------------
|
||||
|
||||
SET_UP_NGINX="${EVECTION_SETUP_NGINX:-}"
|
||||
if [ -z "$SET_UP_NGINX" ] && [ -t 0 ]; then
|
||||
echo
|
||||
read -rp "Set up nginx and an HTTPS certificate now? [y/N]: " SET_UP_NGINX
|
||||
fi
|
||||
|
||||
if [[ "${SET_UP_NGINX:-}" =~ ^[Yy]$ ]]; then
|
||||
if ! command -v nginx >/dev/null 2>&1; then
|
||||
echo "nginx isn't installed — install it first (apt install nginx), then" \
|
||||
"run docs/install.md's nginx section manually." >&2
|
||||
else
|
||||
DOMAIN="${EVECTION_DOMAIN:-}"
|
||||
if [ -z "$DOMAIN" ] && [ -t 0 ]; then
|
||||
read -rp "Domain name for nginx/TLS (must match a hostname in ALLOWED_HOSTS): " DOMAIN
|
||||
fi
|
||||
if [ -z "$DOMAIN" ]; then
|
||||
echo "No domain given — skipping nginx setup. Run docs/install.md's nginx section manually." >&2
|
||||
else
|
||||
sed -e "s/your-domain.example/$DOMAIN/g" \
|
||||
-e "s#/opt/evection#$EVECTION_HOME#g" \
|
||||
"$APP_DIR/docs/deploy/nginx.conf.example" > "/etc/nginx/sites-available/evection"
|
||||
ln -sf /etc/nginx/sites-available/evection /etc/nginx/sites-enabled/evection
|
||||
if nginx -t; then
|
||||
systemctl reload nginx
|
||||
echo "==> nginx configured for $DOMAIN (HTTP only so far)"
|
||||
if command -v certbot >/dev/null 2>&1; then
|
||||
certbot --nginx -d "$DOMAIN" || echo "certbot failed — run it manually: certbot --nginx -d $DOMAIN" >&2
|
||||
else
|
||||
echo "certbot isn't installed. Install it and run:" \
|
||||
"apt install certbot python3-certbot-nginx && certbot --nginx -d $DOMAIN" >&2
|
||||
fi
|
||||
else
|
||||
echo "nginx config test failed — not enabling it. Check /etc/nginx/sites-available/evection." >&2
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "==> Skipping nginx — see docs/install.md step 7 to set it up yourself."
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "==> Done."
|
||||
echo " Visit the site (once nginx/TLS is in place) — the setup wizard creates your admin account."
|
||||
echo " gunicorn is listening on $GUNICORN_BIND — point your reverse proxy at it"
|
||||
echo " (see docs/install.md's \"Reverse proxy\" section) before visiting the site."
|
||||
echo " Once that's in place, the setup wizard creates your admin account on first visit."
|
||||
echo " To upgrade later: sudo ./scripts/upgrade.sh"
|
||||
Reference in new issue
Block a user