6 months ago
502 error. I have tried various methods, but it still happens. Please help me check the problem.
Application failed to respond
This error appears to be caused by the application.
If this is your project, check out your deploy logs to see what went wrong. Refer to our docs on Fixing Common Errors for help, or reach out over our Help Station.
If you are a visitor, please contact the application owner or try again later.
Request ID:
t1jiCxE-QDqETNKQ0_TJvA
28 Replies
6 months ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
6 months ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open brody • 6 months ago
6 months ago
How to make it work properly???
6 months ago
Heyyy!!
A 502 error usually means the app isn't starting up properly. I’d recommend checking your deploy logs first there’s often a clear error there that can point you in the right direction (like a crash, missing env variable, or wrong port). If you’ve already tried a few things, maybe try redeploying or rolling back to a working version. Happy to look at logs with you if you want to share more!
6 months ago
Can I get a bit more info about your project? What language/stack is it? Is it a backend api or a website? What frameworks? Are you using a custom domain?
Any info is helpful 
6 months ago
nextjs is used, API and web, custom domain, 8080 port
6 months ago
https://station.railway.com/questions/bad-request-error-502-0cc25a69
I helped someone recover from the 502 error for the next.js application. You can have a look at that thread, and see if something helps your out. Before that, I receommend you check thta port defined in your server file, & under the Public Networking settings of the app deployed on Railway matches or not!
6 months ago
Public Networking port:8080, Variables port: 8080, next.config.js :
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start -H 0.0.0.0 -p $PORT",
"lint": "next lint"
},
Now it is like this, but it does not work. It was changed to 3000, but it did not work.6 months ago
The project includes a Dockerfile. Does it have anything to do with it?
6 months ago
Yes, can you provide the Dockerfile here!
Also a snippet of your Public Networking settings of your Railway service would be great
6 months ago
dockerfile:
# Muleti-stage Dockerfile for Next.js (standalone) on Railway
# ---- Builder ----
FROM node:22-bookworm-slim AS builder
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
# Build with standalone output (already configured in next.config.js)
RUN npm run build
# ---- Runner ----
FROM node:22-bookworm-slim AS runner
# Optional but recommended: init + fonts for better PDF rendering
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
dumb-init \
ca-certificates \
ffmpeg \
fonts-noto-cjk \
chromium \
libasound2 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libc6 \
libcairo2 \
libcups2 \
libdbus-1-3 \
libexpat1 \
libfontconfig1 \
libgcc1 \
libglib2.0-0 \
libgtk-3-0 \
libnspr4 \
libnss3 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libstdc++6 \
libx11-6 \
libx11-xcb1 \
libxcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxi6 \
libxrandr2 \
libxrender1 \
libxss1 \
libxtst6 \
libxshmfence1 \
libxkbcommon0 \
libdrm2 \
libgbm1 \
libwayland-client0 \
&& rm -rf /var/lib/apt/lists/*
RUN if [ ! -x /usr/bin/chromium ] && [ -x /usr/bin/chromium-browser ]; then ln -sf /usr/bin/chromium-browser /usr/bin/chromium; fi
WORKDIR /app
# Copy public assets
COPY --from=builder /app/public ./public
# Copy standalone server and static files
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
# Non-root for Chrome sandbox friendliness
USER node
# Railway will provide PORT dynamically - no need to EXPOSE since Railway handles port mapping
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["node", "server.js"]
6 months ago
Have you checked the deploy logs? What is the error that is showing up there! And also, please provide the custom domain link to access your application
6 months ago
Build Logs
Deploy Logs
No errors reported
6 months ago
Can you make sure that no other service in your Railway environment is using port 8080? Because that way, the port required by your next.js app would never be free to access.
Also, can you please provide a screenshot of what is in the dropdown of the port number shown under the custom domain of networking settings!
6 months ago
As a last resort, can you please provide the configuration lines for your server js file, which can help us to see a potential reason for error!
6 months ago
my nextjs project dose not have server.js file
6 months ago
Can we have the github repo, if possible?
6 months ago
can you try updating your start script to be:
"start": "node .next/standalone/server.js"fra
can you try updating your start script to be:"start": "node .next/standalone/server.js"
6 months ago
I tried this, but it doesn't work.
6 months ago
This project was previously deployed on Google Cloud Run. Now I'm deploying it on Railway. Are there any special settings required?
6 months ago
no, I'm running nextjs without any issue with a very basic dockerfile and without touching any hostname/port, can you share logs?
are you doing ssr request to other services? are the other services up and running?
also can you try removing:# Optional but recommended: init + fonts for better PDF rendering
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
dumb-init \
ca-certificates \
ffmpeg \
fonts-noto-cjk \
chromium \
libasound2 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libc6 \
libcairo2 \
libcups2 \
libdbus-1-3 \
libexpat1 \
libfontconfig1 \
libgcc1 \
libglib2.0-0 \
libgtk-3-0 \
libnspr4 \
libnss3 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libstdc++6 \
libx11-6 \
libx11-xcb1 \
libxcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxi6 \
libxrandr2 \
libxrender1 \
libxss1 \
libxtst6 \
libxshmfence1 \
libxkbcommon0 \
libdrm2 \
libgbm1 \
libwayland-client0 \
&& rm -rf /var/lib/apt/lists/*
RUN if [ ! -x /usr/bin/chromium ] && [ -x /usr/bin/chromium-browser ]; then ln -sf /usr/bin/chromium-browser /usr/bin/chromium; fi
fra
no, I'm running nextjs without any issue with a very basic dockerfile and without touching any hostname/port, can you share logs? are you doing ssr request to other services? are the other services up and running?also can you try removing:# Optional but recommended: init + fonts for better PDF rendering RUN apt-get update \ && apt-get install -y --no-install-recommends \ dumb-init \ ca-certificates \ ffmpeg \ fonts-noto-cjk \ chromium \ libasound2 \ libatk1.0-0 \ libatk-bridge2.0-0 \ libc6 \ libcairo2 \ libcups2 \ libdbus-1-3 \ libexpat1 \ libfontconfig1 \ libgcc1 \ libglib2.0-0 \ libgtk-3-0 \ libnspr4 \ libnss3 \ libpango-1.0-0 \ libpangocairo-1.0-0 \ libstdc++6 \ libx11-6 \ libx11-xcb1 \ libxcb1 \ libxcomposite1 \ libxcursor1 \ libxdamage1 \ libxext6 \ libxfixes3 \ libxi6 \ libxrandr2 \ libxrender1 \ libxss1 \ libxtst6 \ libxshmfence1 \ libxkbcommon0 \ libdrm2 \ libgbm1 \ libwayland-client0 \ && rm -rf /var/lib/apt/lists/* RUN if [ ! -x /usr/bin/chromium ] && [ -x /usr/bin/chromium-browser ]; then ln -sf /usr/bin/chromium-browser /usr/bin/chromium; fi
6 months ago
it worked. i use default config, and the basic dockerfile.
and then i added the configuration i needed to the dockerfile, and it still worked.
but, there is another problem, the parameters in Variables are not read
for example, i config JWT_SECRET in the Variables, but the Deploy Logs have this error: Error JWT_SECRET environment variable is not set
Attachments
6 months ago
did you redeploy after setting the variable?
fra
did you redeploy after setting the variable?
6 months ago
yes, after setting the variable, i redeploy multiple times, but the same error:Error JWT_SECRET environment variable is not set
6 months ago
can you try logging prcess.env.JWT_SECRET in a server side page or api? don't share it but just check if you see something, are you using library like envalid?
