From e85c407453062fd45688f43def0126b9a893afb0 Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Mon, 8 Jun 2026 16:53:43 +0200 Subject: [PATCH] fix: use dedicated internal port to avoid collision with PORT env MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a platform injects PORT=3000 (e.g. Railway), nginx and Next.js would both try to bind port 3000. Use a dedicated internal port (7901) for the nginx→Next.js proxy to prevent this. --- nginx.conf | 4 +--- scripts/run.sh | 9 +++------ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/nginx.conf b/nginx.conf index 75bbc6004..c3817f17a 100644 --- a/nginx.conf +++ b/nginx.conf @@ -7,7 +7,6 @@ http { listen ${PORT}; listen [::]:${PORT}; - # Route websockets traffic to port 3001 location /websockets { proxy_pass http://${HOSTNAME}:3001; proxy_http_version 1.1; @@ -16,9 +15,8 @@ http { proxy_set_header Host $http_host; } - # Route all other traffic to port 3000 location / { - proxy_pass http://${HOSTNAME}:3000; + proxy_pass http://${HOSTNAME}:${INTERNAL_NEXTJS_PORT}; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; diff --git a/scripts/run.sh b/scripts/run.sh index 3475831ec..bcde4c8bb 100644 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -18,13 +18,10 @@ fi export AUTH_SECRET=$(openssl rand -base64 32) export PORT=${PORT:-7575} +export INTERNAL_NEXTJS_PORT=7901 -# Start nginx proxy -# 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} ${PORT}' < /etc/nginx/templates/nginx.conf > /etc/nginx/nginx.conf +envsubst '${HOSTNAME} ${PORT} ${INTERNAL_NEXTJS_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=$! @@ -38,7 +35,7 @@ else REDIS_PID=$! fi -PORT=3000 node apps/nextjs/server.js & +PORT=$INTERNAL_NEXTJS_PORT node apps/nextjs/server.js & NEXTJS_PID=$! # Function to handle SIGTERM and shut down services