Deploy NGINX Static Site Hosting
Host a static HTML, CSS and JS website on NGINX with HTTPS in one click.
Just deployed
Deploy and Host a Static Site with NGINX on Railway

NGINX is the web server behind a large share of the internet, with 31,000+ GitHub stars on its open-source repo. This template serves your static HTML, CSS, JavaScript and images from NGINX on Railway with HTTPS. Netlify and Vercel's paid plans start at $20/month — a static site on Railway typically costs well under $5/month, and you control the server config.
What This Template Deploys
| Service | Purpose |
|---|---|
| site | nginx:alpine container that serves everything in the repository's site/ folder (port 80, public HTTPS domain). |
One tiny service built from a two-line Dockerfile: FROM nginx:alpine and COPY site /usr/share/nginx/html. Edit the files in site/, push, and Railway redeploys.
About Hosting a Static Site
Static sites don't need much — a fast web server, HTTPS and a way to publish changes. Static hosting platforms make that easy, but their free tiers come with usage caps or non-commercial terms, and you can't change the server configuration.
On Railway, NGINX serves your files from an Alpine container with a public HTTPS domain, and every push to your fork redeploys. Because it's plain NGINX, you can add your own nginx.conf for redirects, caching headers or a single-page-app fallback.
It serves files as they are. There's no build step — put finished HTML, CSS and JS in site/. For React, Vue or Vite apps, build first and copy the output, or use a framework-specific template. Default NGINX settings don't redirect unknown routes to index.html, so add a config if your app uses client-side routing.
Typical cost: under $5/month on Railway for most static sites, within the $5 Hobby plan. Netlify Pro is $20/month, and Vercel's free Hobby plan is for non-commercial use only.
Deploy a Static Site in Under 2 Minutes
- Click Deploy on Railway — Railway forks the repository and builds the container (~1 minute).
- Open the public URL to see the sample page.
- Clone your repository and replace the contents of
site/with your website. - Push to GitHub — Railway redeploys.
- Add a custom domain in the service settings.
No build tools. No server to patch. No vendor-specific config.
Common Use Cases
- Netlify or Vercel alternative — "host static website" with no seat or credit limits
- Landing pages and portfolios — plain HTML and CSS on your own domain
- Documentation sites — publish built docs from any generator
- Pre-built single-page apps — serve a React or Vue
distfolder with an NGINX config - Commercial sites on a cheap plan — no non-commercial restrictions
- Custom server rules — redirects, headers and caching in
nginx.conf
Configuration
| Variable | Required | Description |
|---|---|---|
PORT | Auto-set | 80, the port NGINX listens on. Keep the domain's target port the same. |
Client-side routes need a fallback. If your site uses client-side routing, add an NGINX config with try_files $uri /index.html; or deep links will return 404.
NGINX on Railway vs. Alternatives
| NGINX on Railway | Netlify | Vercel | GitHub Pages | |
|---|---|---|---|---|
| Monthly cost | Under $5 usage | Free (300 credits), $20 Pro | Free (non-commercial), $20 per seat Pro | Free |
| Commercial use | ✅ Yes | ✅ Yes | ❌ Not on Hobby | ⚠️ Limited by policy |
| Custom server config | ✅ Full nginx.conf | ⚠️ Redirect files | ⚠️ JSON config | ❌ No |
| Add a backend or database later | ✅ Same project | ⚠️ Functions only | ⚠️ Functions only | ❌ No |
| Custom domain + HTTPS | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
| License | ✅ BSD-2 NGINX, starter code yours | ❌ Proprietary platform | ❌ Proprietary platform | ❌ Proprietary platform |
Dependencies for Static Site Hosting
- Railway account — Hobby ($5/month) covers most static sites.
- A GitHub account — Railway forks the starter so you own the site.
Deployment Dependencies
- NGINX Docs — server configuration
- nginx Docker image — official image
- Railway Custom Domains — domains and HTTPS
- Railway Docs — deploys and settings
Implementation Details
Railway builds the repository's Dockerfile: the official nginx:alpine image with the site/ folder copied to /usr/share/nginx/html. NGINX listens on port 80 with its default configuration and Railway terminates HTTPS in front of it.
To customise, add an nginx.conf to the repo and copy it to /etc/nginx/conf.d/default.conf in the Dockerfile — for example to add an SPA fallback, cache headers or redirects.
Frequently Asked Questions
What does this NGINX template do?
It serves the static files in the repository's site/ folder from NGINX on a public HTTPS URL, redeploying on every push.
How much does static hosting on Railway cost? Usually under $5/month in usage, covered by the $5 Hobby plan. Netlify Pro and Vercel Pro start at $20/month, and Vercel's free tier is non-commercial.
Why do my React or Vue routes return 404 after refresh?
NGINX's default config only serves real files. Add a config with try_files $uri /index.html; so client-side routes fall back to your app.
Do I lose files when I redeploy?
The site is rebuilt from your repository on every deploy, so your files are whatever is in site/. Don't upload files to the running container — commit them instead.
Can I use a custom domain? Yes. Add it in the service's networking settings and point a CNAME at Railway; HTTPS is issued automatically.
Can I add a backend later? Yes. Add an API service or a database to the same Railway project and call it from your site.
Why Deploy and Host a Static Site with NGINX on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying your static site with NGINX on Railway, you get fast HTTPS hosting with full server control and git-push deploys for a few dollars a month.
Template Content