502
rmfogel
PROOP

20 days ago

Custom domain binat-halev.org returns 502 from Railway edge. Request ID: vEiQDnniQTWfZiDJ21mRUA. Native service URL works fine. Custom domain CNAME target IP 66.33.22.168 is not routing to the service."

$20 Bounty

7 Replies

Railway
BOT

20 days 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 20 days ago


Make sure the port the URL is mapped to is the same port your application is listening to.


rmfogel
PROOP

20 days ago

The port is already correctly configured — PORT=80 is set in the service variables, and the custom domain is mapped to port 80. The application is listening on port 80 and the service works perfectly on its native Railway URL


0x5b62656e5d

Make sure the port the URL is mapped to is the same port your application is listening to.

rmfogel
PROOP

20 days ago

The port is already correctly configured — PORT=80 is set in the service variables, and the custom domain is mapped to port 80. The application is listening on port 80 and the service works perfectly on its native Railway URL


And I assume the pregenerated domain is also listening to port 80?


rmfogel
PROOP

20 days ago

The pregenerated domains have no explicit port configured — Railway auto-detects it. With PORT=80 set as an environment variable, nginx listens on port 80, and the custom domain is also mapped to port 80. The configuration is consistent across both.

The pregenerated domain returns 200, the custom domain returns 502 in 1-2ms with X-Railway-Fallback: true — same port, different result


sheeki03
FREE

20 days ago

Given your follow-up, I would stop treating this as an app port issue.

If the pregenerated Railway domain returns 200, nginx is listening on PORT=80, and the custom domain returns a Railway-edge 502 with X-Railway-Fallback: true, the app is probably reachable. The custom hostname is reaching Railway's edge, but the edge is not routing that hostname to the same service route as the generated domain.

I would check this in order:

  1. In DNS, make sure binat-halev.org is not a manually copied A record to 66.33.22.168. For an apex/root domain, it should point to the exact Railway target shown in the custom-domain screen through CNAME flattening, ALIAS, or ANAME:

binat-halev.org -> .up.railway.app

If your DNS provider shows 66.33.22.168 only because it flattened the Railway target, that can be normal. If you typed 66.33.22.168 yourself as an A record, replace it.

  1. Keep the Railway TXT verification record exactly as shown in the custom-domain screen. The CNAME/ALIAS and the TXT verification record are both part of the custom-domain setup.

  2. In Railway, remove only the binat-halev.org custom-domain entry from Public Networking, add it back on the service whose generated domain returns 200, and map it to port 80 again.

  3. After it verifies, test the custom domain again. If it still returns a fast Railway-edge 502 with X-Railway-Fallback: true while the generated domain still returns 200, then the remaining problem is likely a stale or incorrect custom-domain route on Railway's edge for that hostname, not the container.

So the next user-side fix I would try is deleting and recreating the custom-domain entry with the exact Railway DNS target and TXT record. I would not change the app code while the generated domain is already serving correctly.


ldsjunior-ui
PRO

20 days ago

Root cause: Railway's edge has no verified route for binat-halev.org

The three clues tell the whole story together:

X-Railway-Fallback: true in the response headers means Railway's edge (Cloudflare proxy) received the request for binat-halev.org but had no backend route registered for that hostname. It never forwarded to your container. The fallback fires before your app is involved.

1-2ms response time confirms this. A real 502 from your app takes 100ms+. At 1-2ms, the edge is rejecting at the hostname-routing layer.

Pregenerated domain returns 200 confirms your app, nginx, and PORT=80 are all correct. This is purely a Railway-edge configuration issue.

Why this happens

Railway's edge only routes a custom hostname to your service after two conditions are met:

DNS verification -- Railway must find its TXT record (_railway-verify.binat-halev.org) to confirm you own the domain. Without it, the edge route is never activated, and every request gets X-Railway-Fallback: true.

SSL certificate provisioned -- Railway issues a certificate for the hostname after DNS verification passes. Until the cert is issued, the edge returns 502 for HTTPS requests even if your app is healthy.

Neither of these is about PORT or nginx. Both are Railway-side provisioning steps that happen after DNS is correctly set.

The IP 66.33.22.168 is the likely root cause

For an apex/root domain (binat-halev.org, no www), you cannot use a standard CNAME -- the DNS spec forbids CNAMEs at the zone apex. Providers work around this with ALIAS, ANAME, or CNAME flattening.

If you manually typed 66.33.22.168 as an A record, you bypassed Railway's edge entirely. Requests land on a Railway IP, but Railway's edge routing is keyed on the hostname -- and if the domain was never verified via TXT record, no route exists for it.

Run this to check:

dig binat-halev.org A +short

dig _railway-verify.binat-halev.org TXT +short

Expected output:

A query: an IP that Railway's CDN resolves to (via ALIAS/CNAME flattening -- NOT a manually entered IP)

TXT query: "railway-verify="

If the TXT query returns nothing, the domain was never verified and the edge route was never created.

Fix sequence

Step 1 -- In Railway dashboard: Go to your service > Settings > Networking > Custom Domains. Check whether binat-halev.org shows a green verified checkmark or a pending/warning state. If it shows any non-green status, the edge route is not active.

Step 2 -- Remove and re-add the custom domain in Railway. This forces Railway to re-generate the DNS records you need and re-trigger the provisioning flow. Copy the exact CNAME/ALIAS target and TXT record Railway shows you.

Step 3 -- In your DNS provider: For the apex domain binat-halev.org:

Add an ALIAS or ANAME record (not a CNAME, not a raw A record) pointing to the Railway-provided target (e.g., xxxxx.up.railway.app)

If your DNS provider does not support ALIAS/ANAME, use www.binat-halev.org with a CNAME and redirect bare to www, or use a provider that supports flattening (Cloudflare, Route53, DNSimple)

Add the TXT verification record exactly as Railway shows it: _railway-verify.binat-halev.org with value railway-verify=

Step 4 -- Wait 5-10 minutes. Railway polls for the TXT record. Once it detects it, it activates the edge route and issues the SSL certificate automatically. The custom domain will start returning 200 without any app changes.

What NOT to change

Do not touch your app code, nginx config, or PORT=80 -- those are working correctly. The pregenerated domain proving 200 means everything inside the container is fine. This fix is entirely DNS + Railway dashboard.


Welcome!

Sign in to your Railway account to join the conversation.

Loading...