Help Required: 502 Bad Gateway Error - Flask App Not Accessible on Railway
tayyab-ai
FREEOP

5 months ago

I am facing a 502 Bad Gateway error for my deployed Flask app on Railway. Here is the issue in brief:
My Flask app is hosted together with a Discord bot in a single project, using the waitress server.
The Flask app listens on the port provided by Railway's PORT environment variable.
Deployment logs show the Flask server starts correctly and listens on port 8080.
However, HTTP logs show repeated 502 errors with "connection refused" upstream errors, meaning Railway's proxy cannot connect to my Flask app.
The public URL is properly set and accessible through Railway dashboard.
Discord bot runs without issues.
I verified the service type is HTTP in Railway dashboard.
I use 0.0.0.0 as host and dynamic port from environment in the app.
Please help me verify:
If Railway is routing HTTP traffic properly to my container on the correct port.
Whether there are any platform-side network or proxy issues blocking connection.
Recommended way to deploy combined Discord bot + Flask app on Railway to avoid this 502 error.
I can share logs, repo link, and configurations if needed. Please assist.
Thanks,

$10 Bounty

4 Replies

davidachris
FREE

5 months ago

Under your services Variables Tab click "+ New Variable" add your own defined port. If its 8080 then add PORT=8080 and see if that resolves the issue.


davidachris
FREE

5 months ago

And actually to add on top of that I think Railway listens on just 80, no 8080


tayyab-ai
FREEOP

5 months ago

i tried but still error 502


davidachris
FREE

5 months ago

Last thing I could recommend is specifying the host as "::" instead. This listens on all addresses,

flask --app main run --host="::" --port 8080

Regardless of how you specify the host, if this doesnt resolve the issue then the flask app itself may not actually be running in the container. Have you verified that portion as well?


Loading...