502 gateway error when deploying to production

galpo
FREEOP

13 days ago

Railway keeps changing the port. My app is listening on port 8080, but Railway's target port is probably set to 3000 (the default).

Any idea how to fix this?

Application failed to respond

This error appears to be caused by the application.

If this is your project, check out your deploy logs to see what went wrong. Refer to our docs on Fixing Common Errors for help, or reach out over our Help Station.

If you are a visitor, please contact the application owner or try again later.

Request ID:
yGUPYt6eQweQXVSin6XIxQ

$10 Bounty

10 Replies

monuit
PROTop 5% Contributor

13 days ago

hey, you should instead bind your server to 0.0.0.0:${PORT} (use process.env.PORT instead of hard-coding 8080). railway should auto deploy then and would work fine.

if it still aint working, can you provide your logs?


fra
HOBBYTop 10% Contributor

13 days ago

Another option is to be sure the port exported by your app match the port set in Settings=>Public Network=>Port


13 days ago

Another no-code modification is setting a PORT environment variable to 8080. Railway will automatically detect that port and forward traffic accordingly.


galpo
FREEOP

13 days ago

Thanks everyone. I will try these options


galpo
FREEOP

12 days ago

I am using claude code and it keeps running in a loop


galpo
FREEOP

12 days ago

I need some support from railway team


fra
HOBBYTop 10% Contributor

12 days ago

how do you deploy your app? can you share some code/logs?


galpo
FREEOP

12 days ago

You reached the start of the range

Oct 27, 2025, 9:26 AM

[Region: us-west1]

==============

Using Nixpacks

==============

context: 8sqq-3w9K

╔═════════════════════ Nixpacks v1.38.0 ═════════════════════╗

║ setup │ nodejs_18, bun ║

║────────────────────────────────────────────────────────────║

║ caddy │ pkgs: caddy ║

║ │ cmds: caddy fmt --overwrite /assets/Caddyfile ║

║────────────────────────────────────────────────────────────║

║ install │ npm ci ║

║────────────────────────────────────────────────────────────║

║ build │ bun run build ║

║────────────────────────────────────────────────────────────║

║ start │ npm start ║

╚════════════════════════════════════════════════════════════╝

internal

load build definition from Dockerfile

0ms

internal

load metadata for ghcr.io/railwayapp/nixpacks:ubuntu-1745885067

331ms

internal

load .dockerignore

0ms

internal

load build context

0ms

stage-0

COPY .nixpacks/nixpkgs-ba913eda2df8eb72147259189d55932012df6301.nix .nixpacks/nixpkgs-ba913eda2df8eb72147259189d55932012df6301.nix

21ms

stage-0

RUN nix-env -if .nixpacks/nixpkgs-ba913eda2df8eb72147259189d55932012df6301.nix && nix-collect-garbage -d

31s

36 store paths deleted, 243.63 MiB freed

stage-0

COPY .nixpacks/nixpkgs-f69ae4816bc1b501460ad2c0c63ed0cc4a9b876e.nix .nixpacks/nixpkgs-f69ae4816bc1b501460ad2c0c63ed0cc4a9b876e.nix

37ms

stage-0

RUN nix-env -if .nixpacks/nixpkgs-f69ae4816bc1b501460ad2c0c63ed0cc4a9b876e.nix && nix-collect-garbage -d

33s

30 store paths deleted, 240.05 MiB freed

stage-0

COPY .nixpacks/assets /assets/

63ms

stage-0

COPY . /app/.

20ms

stage-0

RUN caddy fmt --overwrite /assets/Caddyfile

162ms

stage-0

COPY . /app/.

19ms

stage-0

RUN npm ci

7s

Run npm audit for details.

stage-0

COPY . /app/.

122ms

stage-0

RUN bun run build

3s

✓ built in 3.08s

stage-0

RUN printf '\nPATH=/app/node_modules/.bin:$PATH' >> /root/.profile

85ms

stage-0

COPY . /app

57ms

importing to docker

8s

auth

sharing credentials for production-us-west2.railway-registry.com

0ms

=== Successfully Built! ===

Run:

docker run -it production-us-west2.railway-registry.com/a2c5d19e-1d5c-4cf7-ac88-b2efe422e9b2:c9140a34-2e9c-4f31-bc0a-45ab10d03f11

Build time: 149.40 seconds


galpo
FREEOP

12 days ago

I am also not a developer. So, trying to figure things out by myself


Status changed to Open brody 12 days ago


Status changed to Open brody 12 days ago


12 days ago

If you're still unsure, see the attached video on how to tell Railway to forward on port 8080.

Attachments


502 gateway error when deploying to production - Railway Help Station