Use PORT as proxyless host port

This commit is contained in:
cyph3rasi
2026-03-07 17:46:03 -08:00
parent bc4bce950a
commit 7faf536311
4 changed files with 41 additions and 19 deletions
+3 -3
View File
@@ -35,7 +35,7 @@ services:
container_name: synapsis-app container_name: synapsis-app
restart: unless-stopped restart: unless-stopped
ports: ports:
- "127.0.0.1:${APP_HOST_PORT:-3000}:3000" - "127.0.0.1:${PORT:-3000}:${PORT:-3000}"
environment: environment:
DATABASE_URL: postgresql://${DB_USER:-synapsis}:${DB_PASSWORD:-changeme}@postgres:5432/${DB_NAME:-synapsis} DATABASE_URL: postgresql://${DB_USER:-synapsis}:${DB_PASSWORD:-changeme}@postgres:5432/${DB_NAME:-synapsis}
AUTH_SECRET: ${AUTH_SECRET} AUTH_SECRET: ${AUTH_SECRET}
@@ -45,7 +45,7 @@ services:
ALLOW_LOCALHOST: ${ALLOW_LOCALHOST:-} ALLOW_LOCALHOST: ${ALLOW_LOCALHOST:-}
ADMIN_EMAILS: ${ADMIN_EMAILS} ADMIN_EMAILS: ${ADMIN_EMAILS}
BOT_MAX_PER_USER: ${BOT_MAX_PER_USER:-5} BOT_MAX_PER_USER: ${BOT_MAX_PER_USER:-5}
PORT: "3000" PORT: ${PORT:-3000}
NODE_ENV: production NODE_ENV: production
volumes: volumes:
- uploads_data:/app/uploads - uploads_data:/app/uploads
@@ -55,7 +55,7 @@ services:
postgres: postgres:
condition: service_healthy condition: service_healthy
healthcheck: healthcheck:
test: ["CMD-SHELL", "wget -q --spider http://127.0.0.1:3000/api/health || exit 1"] test: ["CMD-SHELL", "wget -q --spider http://127.0.0.1:${PORT:-3000}/api/health || exit 1"]
interval: 30s interval: 30s
timeout: 10s timeout: 10s
retries: 3 retries: 3
+3 -6
View File
@@ -34,14 +34,11 @@ DB_NAME=synapsis
# OPTIONAL: General Settings # OPTIONAL: General Settings
# =========================================== # ===========================================
# Application port - 'auto' scans 3000-3020 for first available (recommended) # Application port.
# Or set a specific port: PORT=3000 # Default install (with bundled Caddy): PORT=auto scans 3000-3020 automatically.
# Existing reverse proxy mode (PROXY=none): use a fixed localhost port, e.g. PORT=3000.
PORT=auto PORT=auto
# External reverse proxy mode only:
# Port on localhost to expose Synapsis for nginx/Traefik/Caddy
# APP_HOST_PORT=3000
# Allow localhost domains in production (set only for local testing) # Allow localhost domains in production (set only for local testing)
# ALLOW_LOCALHOST=1 # ALLOW_LOCALHOST=1
+5 -4
View File
@@ -49,7 +49,6 @@ Optional (advanced):
**Port Configuration:** **Port Configuration:**
- `PORT=auto` (default) — Automatically finds an available port between 3000-3020 - `PORT=auto` (default) — Automatically finds an available port between 3000-3020
- `PORT=3000` — Use a specific port instead - `PORT=3000` — Use a specific port instead
- `APP_HOST_PORT=3000` — Only used in advanced `PROXY=none` installs
--- ---
@@ -66,9 +65,11 @@ docker compose up -d
This mode: This mode:
- skips the bundled Caddy service - skips the bundled Caddy service
- binds Synapsis to `127.0.0.1:${APP_HOST_PORT:-3000}` - binds Synapsis to `127.0.0.1:${PORT:-3000}`
- expects your existing reverse proxy to forward traffic there - expects your existing reverse proxy to forward traffic there
In `PROXY=none` mode, `PORT` is the localhost port your reverse proxy should target. The installer automatically changes `PORT=auto` to `PORT=3000` unless you override it.
Example nginx site: Example nginx site:
```nginx ```nginx
@@ -152,8 +153,8 @@ For the application port itself, `PORT=auto` (default) automatically finds an av
# Check what's using the port # Check what's using the port
sudo netstat -tlnp | grep :3000 sudo netstat -tlnp | grep :3000
# Switch back to auto or choose a different port # Choose a different fixed port in /opt/synapsis/.env
# Edit .env: PORT=auto # Example: PORT=3013
``` ```
### Database connection failed ### Database connection failed
+30 -6
View File
@@ -79,13 +79,24 @@ set_env_value() {
rm -f "${file}.bak" rm -f "${file}.bak"
} }
get_env_value() {
file="$1"
key="$2"
if [ ! -f "$file" ]; then
return 1
fi
sed -n -E "s/^${key}=(.*)$/\\1/p" "$file" | head -n 1
}
generate_db_password() { generate_db_password() {
openssl rand -base64 24 | tr -d '\n' | tr '/+' '_-' | cut -c1-32 openssl rand -base64 24 | tr -d '\n' | tr '/+' '_-' | cut -c1-32
} }
resolve_proxyless_host_port() { resolve_proxyless_port() {
if [ -n "${APP_HOST_PORT:-}" ]; then if [ -n "${PORT:-}" ] && [ "${PORT}" != "auto" ]; then
printf '%s\n' "${APP_HOST_PORT}" printf '%s\n' "${PORT}"
return return
fi fi
@@ -131,7 +142,7 @@ require_command cp
RAW_BASE="https://raw.githubusercontent.com/${REPO}/${REF}" RAW_BASE="https://raw.githubusercontent.com/${REPO}/${REF}"
PROXY="$(normalize_proxy_mode "${PROXY}")" PROXY="$(normalize_proxy_mode "${PROXY}")"
PROXYLESS_HOST_PORT="$(resolve_proxyless_host_port)" PROXYLESS_PORT="$(resolve_proxyless_port)"
echo "========================================" echo "========================================"
echo " Synapsis Docker Installer" echo " Synapsis Docker Installer"
@@ -182,8 +193,21 @@ if [ ! -f "${INSTALL_DIR}/.env" ]; then
set_env_value "${INSTALL_DIR}/.env" "ADMIN_EMAILS" "${ADMIN_EMAILS}" set_env_value "${INSTALL_DIR}/.env" "ADMIN_EMAILS" "${ADMIN_EMAILS}"
echo "📧 Set ADMIN_EMAILS=${ADMIN_EMAILS}" echo "📧 Set ADMIN_EMAILS=${ADMIN_EMAILS}"
fi fi
if [ "${PROXY}" = "none" ]; then
set_env_value "${INSTALL_DIR}/.env" "PORT" "${PROXYLESS_PORT}"
echo "📡 Set PORT=${PROXYLESS_PORT} for proxyless mode"
fi
else else
echo "📝 Existing ${INSTALL_DIR}/.env found, leaving it unchanged" echo "📝 Existing ${INSTALL_DIR}/.env found, leaving it unchanged"
if [ "${PROXY}" = "none" ]; then
current_port="$(get_env_value "${INSTALL_DIR}/.env" "PORT" || true)"
if [ -z "${current_port}" ] || [ "${current_port}" = "auto" ]; then
set_env_value "${INSTALL_DIR}/.env" "PORT" "${PROXYLESS_PORT}"
echo "📡 Updated PORT=${PROXYLESS_PORT} for proxyless mode"
fi
fi
fi fi
echo "" echo ""
@@ -196,6 +220,6 @@ else
echo " 2. Start Synapsis:" echo " 2. Start Synapsis:"
echo " cd ${INSTALL_DIR} && docker compose up -d" echo " cd ${INSTALL_DIR} && docker compose up -d"
echo " 3. Configure your existing reverse proxy to forward to:" echo " 3. Configure your existing reverse proxy to forward to:"
echo " http://127.0.0.1:${PROXYLESS_HOST_PORT}" echo " http://127.0.0.1:${PROXYLESS_PORT}"
echo " (change APP_HOST_PORT in ${INSTALL_DIR}/.env if you want a different localhost port)" echo " (change PORT in ${INSTALL_DIR}/.env if you want a different localhost port)"
fi fi