Exposing Your App
Before your application can say hello, Railway needs to know the IP and port that your application is listening on, in order to expose it to the internet.
The easiest way to get up and running is to have your application listen on
PORT is a Railway-provided environment variable.
Alternatively, you can manually override the
PORT environment variable by adding
PORT to your projects variables page. (Command + K and type
Variables or you can use the keyboard shortcut:
V under your selected project)
Railway services don't obtain a domain automatically, but you'll be notified to set one up as soon as we detect a deployment is listening correctly (as described above). Simply follow the prompts to generate a domain and your app will be exposed to the internet!
One or more custom domains can be added to a Railway service (tied to a specific environment).
Here's how it works:
- Navigate to the Settings tab of your desired service
- Add a custom domain and type in the name
- Add the
CNAMErecord to the DNS settings for your domain
- Wait for Railway to verify your
NOTE!: Changes to DNS settings may take up to 72 hours to propagate worldwide.
NOTE:: freenom is not allowed, and not supported.
Let's Encrypt SSL Certificates
Once a custom domain has been correctly configured, Railway will automatically
generate and apply a Let's Encrypt certificate. This means that any custom
domain on Railway will automatically be accessible
Provider Specific Instructions
If you have proxying enabled on Cloudflare (the orange cloud), you MUST set your SSL/TLS settings to full or above.
If proxying is not enabled, Cloudflare will not associate the domain with your Railway project with the following error.
Also note that if proxying is enabled, you can NOT use a domain deeper than a first level subdomain without Cloudflare's Advanced Certificate Manager. For example, anything falling under *.yourdomain.com can be proxied through Cloudflare without issue, however if you have a custom domain under *.subdomain.yourdomain.com, you MUST disable Cloudflare Proxying and set the CNAME record to DNS Only (the grey cloud), unless you have Cloudflare's Advanced Certificate Manager.
Redirecting a Root Domain Workarounds
Some domain registrars don't fully support CNAME records. As a result - when you add an
@ record for a CNAME, the domain registrar will create an invalid
Registrars that are known to not fully support CNAME records for the root domain include:
Workaround 1 - Cloudflare Proxy
You may also configure Cloudflare proxying for your domain to redirect your domain.
After a custom domain is added to the Railway service follow the instructions listed on Cloudflare's documentation to configure the proxy.
Workaround 2 - Changing your Domain's Nameservers
You can also change your domain's nameservers to point to Cloudflare's nameservers. This will allow you to use a CNAME record for the root domain. Follow the instructions listed on Cloudflare's documentation to change your nameservers.
Edit this file on GitHub