Deploy Static Sites with Zero Configuration and Custom Domains
In this guide, you'll learn how to deploy static websites to Railway with automatic GitHub builds, SSL certificates, and custom domains. All with zero configuration required.
What is Railway?
Railway is a modern deployment platform that lets you deploy static websites and applications without managing servers, configuring load balancers, or learning complex infrastructure. It provides automatic builds, zero-downtime deployments, and built-in CI/CD.
Learn more about Railway's core components and foundations.
Why Choose Railway for Static Hosting?
Railway offers several advantages for static site hosting:
- Zero configuration: Deploy from GitHub without build scripts or complex setup.
- Automatic builds: Every push triggers a new deployment automatically.
- Custom domains: Automatically provisioned SSL certificates and custom domain setup.
- Preview environments: Test changes with automatic PR previews.
- Usage-based pricing: Pay only for what you use, starting at $5/month.
- Private repositories: Deploy from private GitHub repos without additional cost.
Prerequisites
This is a beginner-friendly guide. You'll need:
Deploy a static site on Railway from your own GitHub repository
- Go to railway.com/new
- Select "Deploy from GitHub repo"
- Connect your GitHub account and choose your repository
- Railway will automatically detect the build configuration and deploy your site
Configure a custom domain
Custom domains can be added to any Railway service with automatic SSL certificate provisioning.
-
Navigate to your service settings:
- In your Railway project, click on your deployed service
- Go to the "Settings" tab
- Scroll to the "Networking" section
-
Add your domain:
- Click the "+ Custom Domain" button
- Enter your domain (e.g.,
example.com
) and specify the target port - Railway will provide you with a CNAME record to configure in your DNS provider
-
Configure DNS:
- In your DNS provider (Cloudflare, Namecheap, etc.), create a CNAME record
- Point your domain to the Railway-provided CNAME
- Wait for verification (usually takes a few minutes but can take up to 72 hours)
-
SSL Certificate:
- Railway automatically issues and renews SSL certificates
- Your site will be available at
https://your-domain.com
Learn more about custom domains and SSL configuration in Railway.
Set up preview environments for every pull request for your static site
Railway can automatically create preview environments for every pull request, letting you test changes before merging.
- Configure project settings:
- Go to your Project Settings → Environments tab
- Click "Enable PR Environments"
-
Create a feature branch:
git checkout -b feature/new-page # Make your changes git add . git commit -m "Add new page" git push origin feature/new-page
-
Create a pull request:
- Once you create a pull request, Railway will automatically deploy a preview environment with a unique URL where you can preview your changes.
- When the PR is merged or closed, the PR environment is automatically deleted.
Learn more about using environments and PR environments.
Deploy replicas in different regions for global performance
Railway enables you to deploy your static site across multiple regions for improved global performance and availability.
- Reduced latency: Serve content from the region closest to your users
- High availability: If one region experiences issues, traffic automatically routes to healthy regions
- Better performance: Faster loading times for users worldwide
- Automatic failover: Seamless traffic routing without manual intervention
To get started:
- In your Railway project, click on your deployed service
- Go to the "Settings" tab
- Under "Deploy", go to the "Regions" section and click "+ Add Region"
Railway automatically distributes replicas across available regions and routes traffic to the nearest region.
Each replica runs with the full resource limits of your plan. So if you're on the Pro plan and deploy 3 replicas, you'll get a combined capacity of 96 vCPU and 96 GB RAM across all regions.
Total resources = number of replicas × maximum compute allocation per replica
Learn more about scaling applications and multi-region deployments in Railway.
Alternatively, you can integrate a CDN like Cloudflare for global content delivery and improved performance.
Add Cloudflare as a CDN
While Railway doesn't currently provide a built-in CDN, you can easily integrate a CDN like Cloudflare for global content delivery and improved performance.
-
Add your domain to Cloudflare:
- Sign up for a free Cloudflare account
- Add your Railway domain to Cloudflare
- Update your nameservers as instructed
-
Configure DNS:
- Create a CNAME record in Cloudflare
- Point your domain to your Railway service URL
- Enable "Proxy" (orange cloud) for CDN benefits
-
Verify setup:
- Test your domain to ensure it's working correctly
- Monitor performance improvements in Cloudflare's dashboard
Add API Endpoints with Railway Functions
For static sites that need lightweight API endpoints, Railway Functions enable you to write and deploy code from the Railway canvas without managing infrastructure or creating a git repository.
Railway Functions are Services that run a single file of TypeScript code using the Bun runtime. They're perfect for:
- Form submissions
- Simple API endpoints
- Webhook handlers
- Cron jobs
-
Add a new service:
- In your Railway project, click the "+ Create" button
- Choose "Function" as the service type
- Deploy
-
Write your function:
- Click on the "Source Code" tab
- Write your function code
-
Deploy instantly:
- Press
Cmd+S
(orCtrl+S
) to stage changes - Press
Shift+Enter
to deploy - Your function is live in seconds
- Press
Learn more about Railway Functions.
For most static sites, the Hobby plan with included usage is sufficient. You only pay for resources you actually use.
Learn more about Railway pricing and usage optimization.
Next Steps
Now that you've deployed your static site, explore these resources:
- Add a Database Service for dynamic content
- Monitor your application with built-in metrics
- Set up custom domains and SSL certificates
- Configure environment variables for different environments
- Use Railway Functions for API endpoints
- Optimize performance and usage
Need Help?
If you have any questions or run into issues, you can reach out in the Railway Discord community or on Central Station.
Edit this file on GitHub