Public Networking
Public Networking refers to exposing your application to the internet, to be accessible from the public network.
Port Variable
An essential part of connecting your service to the internet, is properly handling the
PORT
variable.
The easiest way to get up and running is by using the Railway-provided port.
Railway-provided port
As long as you have not defined a
PORT
variable, Railway will provide and expose one for you.
To have your application use the Railway-provided port, you should ensure it is listening on
0.0.0.0:$PORT
, where
PORT
is the Railway-provided environment variable.
Examples
User-defined port
If you prefer to explicitly set a port, you
must
set the
PORT
variable in your service variables to the port on which your service is listening.
For information on how to configure variables, see the Variables guide .
Railway-Provided Domain
Railway services don't obtain a domain automatically, but it is easy to set one up.
To assign a domain to your service, go to your service's settings, find the Networking -> Public Networking section, and choose
Generate Domain
.
Automated prompt
If Railway detects that a deployed service is listening correctly (as described above), you will see a prompt on the service tile in the canvas, and within the service panel.
Simply follow the prompts to generate a domain and your app will be exposed to the internet.
Don't see the Generate Domain Button?
If you have previously assigned a TCP Proxy to your service, you will not see the
Generate Domain
option. You must remove the TCP Proxy (click the Trashcan icon), then you can add a domain.
Custom Domains
Custom domains can be added to a Railway service and environment.
Navigate to the Settings tab of your desired service
Click
+ Custom Domain
in the Public Networking section of Settings
Type in the custom domain (wildcard domains are supported, see below for more details)
In your DNS provider (Cloudflare, DNSimple, Namecheap, etc), update your domain's DNS settings by adding the appropriate DNS record(s) and associating it with the domain provided by Railway, e.g.,
abc123.up.railway.app
Wait for Railway to verify your record. When verified, you will see a greencheck mark next to the domain(s) -
Note that changes to DNS settings may take up to 72 hours to propagate worldwide.
Important Considerations
yourdomain.com
and
www.yourdomain.com
as these are considered two distinct custom domains.
Wildcard Domains
Wildcard domains allow for flexible subdomain management. There are a few important things to know when using them:
authorize.railwaydns.net
is not proxied by your provider (eg: Cloudflare). This is required for the verification process to work.
*.yourdomain.com
or
*.subdomain.yourdomain.com
).
When you add a wildcard domain, you will be provided with two domains for which you should add two CNAME records -
One record is for the wildcard domain, and one for the _acme-challenge. The _acme-challenge CNAME is required for Railway to issue the SSL Certificate for your domain.
Wildcard Domains on Cloudflare
If you have a wildcard domain on Cloudflare, you must:
Turn off Cloudflare proxying is on the
_acme-challenge
record (disable the orange cloud)
Disable Cloudflare's Universal SSL
Target Ports
Target Ports, or Magic Ports, correlate a single domain to a specific internal port that the application listens on, enabling you to expose multiple HTTP ports through the use of multiple domains.
Example -
https://example.com/
→
:8080
https://management.example.com/
→
:9000
When you first generate a Railway-provided domain, if your application listens on a single port, Railway's magic automatically detects and sets it as the domain's target port. If your app listens on multiple ports, you're provided with a list to choose from.
When you add a custom domain, you're given a list of ports to choose from, and the selected port will handle all traffic routed to the domain. You can also specify a custom port if needed.
These target ports inform Railway which public domain corresponds to each internal port, ensuring that traffic from a specific domain is correctly routed to your application.
You can change the automatically detected or manually set port at any time by clicking the edit icon next to the domain.
Adding a custom domain
When adding a root or apex domain to your Railway service, you must ensure that you add the appropriate DNS record to the domain within your DNS provider. At this time, Railway supports CNAME Flattening and ALIAS records.
Additional context
Generally, direct CNAME records at the root or apex level are incompatible with DNS standards (which assert that you should use an "A" or "AAAA" record). However, given the dynamic nature of the modern web and PaaS providers like Railway, some DNS providers have incorporated workarounds enabling CNAME-like records to be associated with root domains. Check out RFC 1912 if you're interested in digging into this topic.
Choosing the correct record type
The type of record to create is entirely dependent on your DNS provider. Here are some examples -
In contrast there are many nameservers that don't support CNAME flattening or dynamic ALIAS records -
AWS Route 53 Hostinger GoDaddy NameSilo Hurricane ElectricWorkaround - Changing your Domain's Nameservers
If your DNS provider doesn't support CNAME Flattening or dynamic ALIAS records at the root, 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 .
Adding a root domain with www subdomain to Cloudflare
If you want to add your root domain (e.g.,
mydomain.com
) and the
www.
subdomain to Cloudflare and redirect all
www.
traffic to the root domain:
mydomain.com
). Copy the
value
field. This will be in the form:
abc123.up.railway.app
.
CNAME
DNS record to Cloudflare:
Name
→
@
.
Target
→ the
value
field from Railway.
Proxy status
→
on
, should display an orange cloud.
Name
will automatically update to your root domain (e.g.,
mydomain.com
).
CNAME
DNS record to Cloudflare:
Name
→
www
.
Target
→
@
Proxy status:
→ on, should display an orange cloud.
Target
value to your root domain.
SSL/TLS -> Overview
.
Full
, or
Full (strict)
.
SSL/TLS -> Edge Certificates
.
Universal SSL
.
Cloudflare proxy detected
on your Custom Domain in Railway with a green cloud.
Bulk Redirects
.
Create Bulk Redirect List
.
www-redirect
.
Or, manually add URL redirects
.
Source URL
:
https://www.mydomain.com
.
Target URL
:
https://mydomain.com
with status
301
.
Preserve query string
,
Include subdomains
,
Subpath matching
,
Preserve path suffix
)
Next
, then
Save and Deploy
.
Note:
DNS changes may take some time to propagate. You may want to refresh your DNS cache by using commands like
ipconfig /flushdns
on Windows or
dscacheutil -flushcache
on macOS. Testing the URLs in an incognito window can also help verify changes.
TCP Proxying
You can proxy TCP traffic to your service by creating a TCP proxy in the service settings. Enter the port that you want traffic proxied to, Railway will generate a domain and port for you to use. All traffic sent to
domain:port
will be proxied to your service. This is useful for services that don't support HTTP, such as databases.
Currently we use a random load balancing strategy for TCP traffic.
Using HTTP and TCP together
At the moment, Railway does not support exposing both HTTP and TCP over public networking, in a single service. Therefore, if you have a domain assigned, you will not see the option to enable TCP Proxy, and vice-versa. Meaning, you will need to remove one before you can enable the other.
If you have a usecase that requires exposing both HTTP and TCP over public networking, in one service, let us know !
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
via
https://
.
External SSL Certificates
We currently do not support external SSL certificates since we provision one for you.
Provider Specific Instructions
If you have proxying enabled on Cloudflare (the orange cloud), you MUST set your SSL/TLS settings to full or above.