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.
Pinned Solution
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
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
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
2 months ago
hope this help you, if not which dns provider are you using? that would help narrow it down further
2 months ago
namecheap
herocodes770
namecheap
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
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.
2 months ago
ok can you share what records you currently have on the @ host in namecheap ?
2 months ago
Brevo for emails.
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.
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?
2 months ago
- Port: Not hardcoded. It comes from the
PORTenvironment variable. - Default:
80whenPORTis not set. - Flow:
docker-entrypoint.shsetsPORT="${PORT:-80}"(default 80).nginx.conf.templateuseslisten ${PORT};.- The entrypoint runs
sedto 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}"
2 months ago
And it's the same port 80 that I have configured on Railway.
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
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
