502 Bad Gateway on NestJS + Postgres Deployment
den4k-pr
FREEOP

3 months ago

Hello Railway Support,

I deployed a NestJS application with Postgres on Railway. The server starts successfully according to the logs, and it connects to the database without issues. Locally, everything works perfectly. However, when accessing the endpoints through Railway, I consistently get 502 Bad Gateway errors.

All my settings have been double-checked:

  • The app uses process.env.PORT for the port.

  • CORS and rate limiting are configured.

  • Validation pipes and Swagger are set up.

  • Postgres connection is successful.

Logs indicate the application starts correctly:

✅ Connection to database successful
✅ Server running on port 8080

Requests to endpoints like /auth/login or /test return 502. It seems that the Railway edge cannot reach the application, although the server itself appears to be running.

Could you please help me identify why the edge cannot connect to my deployed NestJS application and resolve the 502 errors?

Thank you for your assistance.

$10 Bounty

7 Replies

Railway
BOT

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


den4k-pr
FREEOP

3 months ago

.


noahd
EMPLOYEE

3 months ago

Hey there! Is your process binding to 0.0.0.0?


den4k-pr
FREEOP

3 months ago

Yes


noahd

Hey there! Is your process binding to 0.0.0.0?

den4k-pr
FREEOP

3 months ago

Even if I don't use 0.0.0.0, just the port, it doesn't work. I've tried everything.


kampouse
HOBBY

3 months ago

Have you tried a fresh template and seen a difference from your setup and there?

I was able to get a 502 if the Nest server is not healthy.

What kind of logging is your server spitting out when you started it?


jack
PRO

3 months ago

When trying to access the endpoints through Railway, do you mean on other services? Are you using 0.0.0.0:8080 to try to access that service from another service? If so, try using the private networking address in the service settings such as nextjs:8080, and be sure to prefix the http:// protocol.

If you're trying to access that endpoint from a public networking address, does that work? Is the port set under the public networking domain correct? I'm not sure I completely understand what you're trying to do when you're getting this issue. Is the public networking address throwing an error and not resolving to your server port?


Loading...