Custom Domain returning 502
herocodes770
PROOP

2 months ago

Hello

My custom domain is currentyl returning 502. Everything has been setup and strangely the subdomains work. However the main domain keeps returning 502. Been like this for a while.

Solved$10 Bounty

Pinned Solution

ilyass012
FREE

2 months ago

since your backend works but your frontend nginx container gives 502, can you check your nginx.conf.template , is the listen directive set to listen ${PORT} on 0.0.0.0 or just on a specific interface? railway requires the app to bind to 0.0.0.0:$PORT to accept traffic. also worth double checking that your docker-entrypoint.sh is actually replacing ${PORT} in the template correctly at runtime , if the sed substitution silently fails, nginx could be falling back to port 80 from your local nginx.conf instead of using railway's injected port

13 Replies

Railway
BOT

2 months ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open Railway 2 months ago


ilyass012
FREE

2 months ago

the most common reason for this issue is a dns misconfiguration at the apex/root level

two things to check:

first, if you're on cloudflare, make sure the proxy is turned off (set to dns only, grey cloud) and your ssl/tls mode is set to "full" not "full strict"

second, make sure your app is listening on railway's PORT environment variable and not a hardcoded port like 3000 or 8080, railway injects the port at runtime so if it's hardcoded it won't work even if dns is fine


ilyass012
FREE

2 months ago

hope this help you, if not which dns provider are you using? that would help narrow it down further


herocodes770
PROOP

2 months ago

namecheap


herocodes770

namecheap

ilyass012
FREE

2 months ago

for namecheap, set up a cname record on the root domain (@) pointing to your railway-provided domain (something like abc123.up.railway.app)

can you check in your namecheap dns settings if that cname record on @ is actually there and pointing to the correct railway value? also make sure there are no conflicting a records or redirect records set for the same @ host, namecheap warns those can conflict


herocodes770
PROOP

2 months ago

It is. It is pointing to the correct railway provided domain. There is another platform using the @ however that is a TXT record and not a CNAME.


herocodes770

It is. It is pointing to the correct railway provided domain. There is another platform using the @ however that is a TXT record and not a CNAME.

ilyass012
FREE

2 months ago

ok can you share what records you currently have on the @ host in namecheap ?


herocodes770
PROOP

2 months ago

Brevo for emails.


herocodes770
PROOP

2 months ago

It's just that. And then I have setup the rest for Railway.

One for the main domain and one for the backend(which works. I am able to reach the domain successfully and get my docs)

However the main domain pointing to my web application throws the 502.


ilyass012
FREE

2 months ago

so the dns is likely fine then since the backend works. this points to an application-level issue not dns, is your frontend app listening on the PORT environment variable that railway provides, or is it hardcoded to a specific port?


herocodes770
PROOP

2 months ago

  • Port: Not hardcoded. It comes from the PORT environment variable.
  • Default:80 when PORT is not set.
  • Flow:
    1. docker-entrypoint.sh sets PORT="${PORT:-80}" (default 80).
    2. nginx.conf.template uses listen ${PORT};.
    3. The entrypoint runs sed to replace ${PORT} in the template before starting nginx.

Local dev (Vite)

  • Vite dev server typically uses port 5173 (its default).

Summary

FilePurposenginx.conf.templatelisten ${PORT}; — configurable via envnginx.conflisten 80; — hardcoded for local usedocker-entrypoint.shPORT="${PORT:-80}"


herocodes770
PROOP

2 months ago

And it's the same port 80 that I have configured on Railway.


ilyass012
FREE

2 months ago

since your backend works but your frontend nginx container gives 502, can you check your nginx.conf.template , is the listen directive set to listen ${PORT} on 0.0.0.0 or just on a specific interface? railway requires the app to bind to 0.0.0.0:$PORT to accept traffic. also worth double checking that your docker-entrypoint.sh is actually replacing ${PORT} in the template correctly at runtime , if the sed substitution silently fails, nginx could be falling back to port 80 from your local nginx.conf instead of using railway's injected port


herocodes770
PROOP

2 months ago

This resolved it. It was supposed to be listening to 8080 but it was set to 80 on Railway

Thank you very much!


Status changed to Solved brody 2 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...