From e004afa80612f4dde8cc00f597e6e0a14195fc8b Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Mon, 8 Jun 2026 16:44:16 +0200 Subject: [PATCH] feat: respect PORT env variable for Coolify preview deployments Nginx now listens on ${PORT} (default 7575) instead of hardcoded 7575, so Coolify can inject a unique port per preview container. The internal Next.js server is pinned to port 3000 to avoid conflicting with nginx. --- Dockerfile | 3 +++ apps/nextjs/package.json | 2 +- development/docker-run.cmd | 2 +- nginx.conf | 4 ++-- scripts/run.sh | 8 +++++--- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index fd852fd9e..a619017f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -65,5 +65,8 @@ ENV AUTH_PROVIDERS='credentials' ENV REDIS_IS_EXTERNAL='false' ENV NODE_ENV='production' +ARG PORT=7575 +EXPOSE ${PORT} + ENTRYPOINT [ "/app/entrypoint.sh" ] CMD ["sh", "run.sh"] diff --git a/apps/nextjs/package.json b/apps/nextjs/package.json index 6f37d0ef9..cab9c730b 100644 --- a/apps/nextjs/package.json +++ b/apps/nextjs/package.json @@ -9,7 +9,7 @@ "dev": "pnpm with-env next dev", "format": "oxfmt .", "lint": "oxlint", - "start": "pnpm with-env next start", + "start": "pnpm with-env next start -p ${PORT:-3000}", "typecheck": "tsc --noEmit", "with-env": "dotenv -e ../../.env --" }, diff --git a/development/docker-run.cmd b/development/docker-run.cmd index 2ef22223b..334a8877d 100644 --- a/development/docker-run.cmd +++ b/development/docker-run.cmd @@ -1,2 +1,2 @@ :: Please do not run this command in production. It is only for local testing. -docker run -p 7575:7575 -e SECRET_ENCRYPTION_KEY=0000000000000000000000000000000000000000000000000000000000000000 homarr:latest \ No newline at end of file +docker run -p 7575:7575 -e PORT=7575 -e SECRET_ENCRYPTION_KEY=0000000000000000000000000000000000000000000000000000000000000000 homarr:latest \ No newline at end of file diff --git a/nginx.conf b/nginx.conf index 4b82c8ca5..75bbc6004 100644 --- a/nginx.conf +++ b/nginx.conf @@ -4,8 +4,8 @@ events { http { server { - listen 7575; - listen [::]:7575; + listen ${PORT}; + listen [::]:${PORT}; # Route websockets traffic to port 3001 location /websockets { diff --git a/scripts/run.sh b/scripts/run.sh index a9c13a8e1..3475831ec 100644 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -17,12 +17,14 @@ fi # Auth secret is generated every time the container starts as it is required, but not used because we don't need JWTs or Mail hashing export AUTH_SECRET=$(openssl rand -base64 32) +export PORT=${PORT:-7575} + # Start nginx proxy -# 1. Replace the HOSTNAME in the nginx template file +# 1. Replace the HOSTNAME and PORT in the nginx template file # 2. Create the nginx configuration file from the template # 3. Start the nginx server export HOSTNAME -envsubst '${HOSTNAME}' < /etc/nginx/templates/nginx.conf > /etc/nginx/nginx.conf +envsubst '${HOSTNAME} ${PORT}' < /etc/nginx/templates/nginx.conf > /etc/nginx/nginx.conf # Start services in the background and store their PIDs nginx -g 'daemon off;' & NGINX_PID=$! @@ -36,7 +38,7 @@ else REDIS_PID=$! fi -node apps/nextjs/server.js & +PORT=3000 node apps/nextjs/server.js & NEXTJS_PID=$! # Function to handle SIGTERM and shut down services