Connecting Railway to CloudFront

I was really struggled so I leave it for anyone else facing the same issue.

Document:
https://docs.railway.app/tutorials/add-a-cdn-using-cloudfront

My 1st solution:
https://help.railway.app/questions/how-i-can-add-cloud-front-671b8863

The approach d…


This content originally appeared on DEV Community and was authored by Hiroki Isogai

I was really struggled so I leave it for anyone else facing the same issue.

Document:
https://docs.railway.app/tutorials/add-a-cdn-using-cloudfront

My 1st solution:
https://help.railway.app/questions/how-i-can-add-cloud-front-671b8863

The approach described in the documentation, which doesn't forward viewer headers to the origin server, caused issues as the application identified the traffic as coming directly from Railway, resulting in some processing problems. While this setup worked fine with simple Node.js backend APIs, when deploying Laravel applications, I encountered issues where asset URLs and Inertia link domains were incorrectly set to Railway's domain.

While the asset URLs could potentially be fixed using ASSET_URL, the Inertia-related issues seemed more challenging to resolve. I was looking for a way to forward the original viewer's headers while ensuring requests would work properly.

Solution

  1. Set up a Custom Domain (e.g. xxx.example.com) in Railway
    • Ignore the CNAME DNS settings shown in Railway
    • Copy the generated CNAME value (youroriginal.up.railway.app)
  2. Create a Cloudfront distribution and set youroriginal.up.railway.app as the origin
  3. When configuring the Behaviour settings, set the Origin request policy (optional) to "AllViewer". This is necessary to set All viewer headers to Headers section.
  4. Configure your DNS settings to create a CNAME record pointing your custom domain (xxx.example.com) to your Cloudfront distribution domain (xxx.cloudfront.net)
  5. You should now be able to connect through your custom domain
    • You can ignore the "Waiting for DNS" status in Railway


This content originally appeared on DEV Community and was authored by Hiroki Isogai


Print Share Comment Cite Upload Translate Updates
APA

Hiroki Isogai | Sciencx (2024-11-10T15:12:04+00:00) Connecting Railway to CloudFront. Retrieved from https://www.scien.cx/2024/11/10/connecting-railway-to-cloudfront/

MLA
" » Connecting Railway to CloudFront." Hiroki Isogai | Sciencx - Sunday November 10, 2024, https://www.scien.cx/2024/11/10/connecting-railway-to-cloudfront/
HARVARD
Hiroki Isogai | Sciencx Sunday November 10, 2024 » Connecting Railway to CloudFront., viewed ,<https://www.scien.cx/2024/11/10/connecting-railway-to-cloudfront/>
VANCOUVER
Hiroki Isogai | Sciencx - » Connecting Railway to CloudFront. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/11/10/connecting-railway-to-cloudfront/
CHICAGO
" » Connecting Railway to CloudFront." Hiroki Isogai | Sciencx - Accessed . https://www.scien.cx/2024/11/10/connecting-railway-to-cloudfront/
IEEE
" » Connecting Railway to CloudFront." Hiroki Isogai | Sciencx [Online]. Available: https://www.scien.cx/2024/11/10/connecting-railway-to-cloudfront/. [Accessed: ]
rf:citation
» Connecting Railway to CloudFront | Hiroki Isogai | Sciencx | https://www.scien.cx/2024/11/10/connecting-railway-to-cloudfront/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.