fix: use dedicated internal port to avoid collision with PORT env
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.
This commit is contained in:
2 files changed
+4
-9
No files matched your search
+1
-3
@@ -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;
|
||||
|
||||
+3
-6
@@ -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
|
||||
|
||||
Reference in new issue
Block a user