Successful deployment but 502 Bad Gateway
akinloluwami
HOBBYOP

3 months ago

I deployed an Astro app, deployments is fine, deploy logs is fine but I get a 502 Bad Gateway error when I go to the deployment url.
The app runs on port 4321 and the is setting in the Railway settings.
What could be the issue?

$10 Bounty

2 Replies

bytekeim
PRO

3 months ago

hey! 502 means ur app built successfully but Railway can't connect to it. this usually happens when Astro isn't binding to the right host.

add this environment variable in Railway:

HOST=0.0.0.0

Astro by default binds to localhost which Railway can't access from outside the container. setting HOST=0.0.0.0 makes it listen on all network interfaces.

also double-check:

  1. your start command should be npm run preview (not npm run dev)

  2. make sure you're using the Node adapter in your astro.config.mjs:

import node from '@astrojs/node';

export default defineConfig({
  output: 'server',
  adapter: node({
    mode: 'standalone'
  })
});
  1. PORT is already set to 4321

after adding HOST=0.0.0.0, redeploy and it should work. if it still doesn't, share your deploy logs and I'll take a look!


akinloluwami
HOBBYOP

3 months ago

Thank you so much. I works now.


Loading...