9 days ago
I have the following issue: the site was in production without a registered domain. In this case, the favicon.ico was appearing normally, directly through Railway. As soon as I registered the domain and published it, using Cloudflare's DNS, the favicon no longer appears. I've already tried several things that were suggested in the documentation from both Cloudflare and Railway, but nothing worked. Does anyone have any idea how to solve this?
1 Replies
9 days ago
I would debug this as a cache/path issue first, not a Railway deployment issue, since it worked on the Railway domain and only changed when the hostname moved behind Cloudflare.
The first thing I would check is what the custom domain actually returns for the icon:
curl -I https://yourdomain.com/favicon.ico
You want that to be a `200`, not a `301`, `302`, `404`, or HTML response. The headers to look at are:
content-type cache-control cf-cache-status
If that returns a 404, the fix is in the app: make sure the file is actually served at the root path for the custom domain, usually `/favicon.ico`, and make sure the page uses a root-relative icon URL like:
<link rel="icon" href="/favicon.ico">
not a URL pointing at the old Railway domain or a relative path that changes depending on the route.
If `curl` returns the right file but the browser still does not show it, it is probably cached. Cloudflare caches `.ico` files by default, and browsers also cache favicons pretty aggressively. I would do both of these:
1. In Cloudflare, purge the single URL for `https://yourdomain.com/favicon.ico\`
2. Change the icon URL temporarily to a versioned URL, for example:
<link rel="icon" href="/favicon.ico?v=2">
Then test in a private/incognito window.
Also check the Cloudflare/Railway domain setup while you are there. Railway's docs say custom domains need the exact `CNAME` and `TXT` records Railway gives you. If the Cloudflare proxy is enabled, Railway's docs also say Cloudflare SSL/TLS should be set to `Full`, not `Full (Strict)`. You may need to refresh Clouldflare's caching mechanism when making any changes.
So my order would be:
curl -I https://yourdomain.com/favicon.ico
If it is not `200`, fix the app route or favicon path.
If it is `200` but stale, purge that one URL in Cloudflare and version the favicon URL.
If the whole custom domain behaves differently than the Railway domain, re-check the Railway `CNAME`/`TXT` records and Cloudflare SSL mode.
Docs:
https://docs.railway.com/networking/domains/working-with-domains
https://developers.cloudflare.com/cache/concepts/default-cache-behavior/