a year ago
Hi everyone,
I’m deploying a Flask/Gunicorn app on Railway and consistently getting a 502 Bad Gateway error when I try to access the public URL (on port 8080). Internally, everything works: using railway run bash and curling http://localhost:8080 returns the correct responses. However, from the outside (e.g., “https://myapp.up.railway.app”), I only see a 502 error. I cannot use the public URL to interact with my project endpoints at all.
What I’ve Tried So Far:
• Confirmed Gunicorn is bound to 0.0.0.0:8080.
• Verified that $PORT is set to 8080.
• Added a simple /health endpoint (still returns 502 externally).
• Checked logs for errors; nothing conclusive shows up.
• Removed large files to avoid timeouts, then redeployed. directory is significantly less than 45mb
• Used both railway link and railway redeploy to ensure my latest code is uploaded.
Despite these steps, the public-facing endpoint always fails with a 502. Does anyone have insight into what else I can check or configure on Railway to get around this issue? .
9 Replies
a year ago
Is your public domain on the metal edge? you can check by going to your domain and seeing if there's a "Metal Edge" descriptor below it
dev
Is your public domain on the metal edge? you can check by going to your domain and seeing if there's a "Metal Edge" descriptor below it
a year ago
It doesn’t appear to be the case. The domain is inaccessible by browser but there’s nothing in the railway deployment details that mention metal edge.
a year ago
Oh okay, my thought was that you might've been using metal edge with a legacy runtime which can cause persistent 502 errors
only other thing I can think of is that maybe the domain you have was assigned to a different port manually, make sure your domain's port aligns with the port your app's using (8080)
and if that's not the case then i'm out of ideas
dev
Oh okay, my thought was that you might've been using metal edge with a legacy runtime which can cause persistent 502 errorsonly other thing I can think of is that maybe the domain you have was assigned to a different port manually, make sure your domain's port aligns with the port your app's using (8080)and if that's not the case then i'm out of ideas
a year ago
the domain also uses port 8080, and I’ve assured that all relevant flask processes listen+serve port 8080. The only difference is a psql database service url that operates a different port. It’s odd because I can interact individually w the flask service on a local host and as well with the psql database service but I cannot seem to make external requests to this port 8080-bound flask service on railway..
Might I ask why the use of metal edge with legacy runtime would cause 502 errors? Maybe there’s something similar going wrong with my flask service on railway?
peacefrom-earth
the domain also uses port 8080, and I’ve assured that all relevant flask processes listen+serve port 8080. The only difference is a psql database service url that operates a different port. It’s odd because I can interact individually w the flask service on a local host and as well with the psql database service but I cannot seem to make external requests to this port 8080-bound flask service on railway..Might I ask why the use of metal edge with legacy runtime would cause 502 errors? Maybe there’s something similar going wrong with my flask service on railway?
a year ago
curl test of my endpoint tells me I am using railway-edge
HTTP/2 502
content-type: application/json
server: railway-edge
x-railway-edge: railway/us-east4
x-railway-fallback: true
x-railway-request-id: NQQkc1YjTm6G95ThiCXwDQ_3118653284
content-length: 120
a year ago
You are getting a 502 because your app is not running, please take note of the deployment status - COMPLETED
This means there is nothing running for that deployment anymore, likely because your app exited with a non error code.
Status changed to Awaiting User Response Railway • about 1 year ago
a year ago
Right, app is definitely not running. Initially logs showed it starting container, being assigned to port 8080, then stopping container. To address this, I adjusted the dockerfile of the directory to use an entrypoint file, “run.sh”, in place of an explicit call to gunicorn. Logs show that app exits still, showing “complete”, but without the container stopping.
Status changed to Awaiting Railway Response Railway • about 1 year ago
a year ago
That said, URL is still entirely inaccessible
6 months ago
So I have the same issue and what I have found is that even though I am not commanding railway to use docker it is, Nixpacks system detected my project as needing a containerized build, and it’s generating a Docker image behind the scenes that auto-generated container will default to port 8080 — which explains why Uvicorn is binding to 8080 and why you’re getting a 502. To get around this use a startup command that binds it to port 8000 like uvicorn main:app --host 0.0.0.0 --port 8000
