502 Bad Gateway Error Despite Server Running Successfully
0xlareina
HOBBYOP

2 months ago

Hi Railway Support Team,

I'm experiencing a persistent 502 Bad Gateway error on my backend service, even though the deployment logs clearly show the server is running successfully.

Service Details:

Issue Description:

  1. The server starts successfully and logs show it's listening on port 8080

  2. Heartbeat logs confirm the process is continuously running

  3. However, all HTTP requests return 502 Bad Gateway

  4. The HTTP logs show: GET / 502 for all endpoints

What I've Tried:

  • Removed manual PORT variable and let Railway auto-assign (it assigned 8080)

  • Confirmed server binds to 0.0.0.0:8080

  • Tested with minimal HTTP server to rule out application code issues

  • Server process remains healthy with continuous heartbeat logs

Deploy Logs (showing successful startup):

> node minimal.js
[2025-09-22T05:15:17.484Z] Starting minimal server...
[2025-09-22T05:15:17.491Z] Server listening on 0.0.0.0:8080
[2025-09-22T05:15:22.495Z] Heartbeat - server still running
[2025-09-22T05:15:27.501Z] Heartbeat - server still running

HTTP Logs (showing 502 errors):

GET / 502 168ms
GET /health 502 3ms

The server is clearly running and healthy, but Railway's proxy layer seems unable to route traffic to it. This appears to be a platform-level routing issue rather than an application problem.

Could you please investigate why the proxy cannot connect to my running service?

Request ID from one of the 502 errors: jTzKFpGtSRuQyYluacI7Nw

Thank you for your help!

Solved$10 Bounty

9 Replies

Railway
BOT

2 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!


brody
EMPLOYEE

2 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 3 months ago


noahd
EMPLOYEE

2 months ago

Howdy hey!
I've had this happen a few times and its usually an odd problem.
Can you confirm, in your minimal.js service are you binding to a .env port or a constant value.
If a value defined in .env, I'd suggest temporarily hard coding 8080 for debugging purposes. In both Railway variables and service.


thabanghutamo
FREE

2 months ago

In your server code, replace hardcoded ports with process.env.PORT:

const express = require("express");
const app = express();

const PORT = process.env.PORT || 8080; // use Railway's injected port
app.listen(PORT, "0.0.0.0", () => {
  console.log(`Server listening on 0.0.0.0:${PORT}`);

rishimohan
PRO

2 months ago

@error Is this not because of the outage going on currently?


rishimohan

@error Is this not because of the outage going on currently?

noahd
EMPLOYEE

2 months ago

The outage is currently resolved as can be seen: https://status.railway.com/cmfv2ciuy00krz1jvwfghr4gz
This thread is dated 6-7 hours before this outage was reported.
Unsure if its a similar issue.


rishimohan
PRO

2 months ago

Might be, but the outage is definitely not resolved. Without any change, I'm still getting errors while starting my app


noahd
EMPLOYEE

2 months ago

If you're having any major issues with deployments feel free to create a new thread! Would be happy to provide any support in a new thread.

According to the status page this has been resolved. I am personally not experiencing any issues either.

Attachments


0xlareina
HOBBYOP

2 months ago

Fixed now after filling the right port in the network setting.


noahd
EMPLOYEE

2 months ago

Glad to hear!


Status changed to Solved noahd 3 months ago


Loading...