
Deploy Caddy: Reverse Proxy & Web Server for Private Railway Apps
Put one public Caddy front door in front of your private services.
Just deployed
Deploy and Host Caddy on Railway

Caddy is an open source web server and reverse proxy known for its simple configuration file, the Caddyfile, and sensible defaults. This template runs Caddy as a single public front door on Railway: point it at a private service and Caddy forwards traffic to it over Railway's private network, compresses responses and adds forwarding headers. Leave the target empty and it serves static files instead. Caddy is Apache-2.0 licensed with about 79,000 GitHub stars, and v2.11.9 shipped in November 2026; this template runs Caddy 2.11.7. Railway terminates HTTPS at its edge, so you get a TLS-protected domain without managing certificates. Commercial gateways and load balancers often bill per hour plus traffic. Caddy on Railway usually costs only a few dollars a month because it uses very little memory.
What This Template Deploys
| Service | Purpose |
|---|---|
| caddy | ghcr.io/onepush-dev/caddy:2.11.7, the official Caddy build with a small Caddyfile. Listens on port 8080 with a public domain and a health check on /. |
There is no volume and no database. The whole configuration is two variables, and anything more advanced lives in a Caddyfile you can fork and edit.
About Hosting Caddy
Many apps on Railway should not face the internet directly: an admin dashboard without a login, an internal API, or a service that only speaks plain HTTP. Putting a small proxy in front lets you keep those services private while one hardened entry point handles public traffic.
Reverse proxy. Set UPSTREAM to a private address such as myapp.railway.internal:3000, and Caddy forwards every request to it, adding X-Forwarded-Proto and X-Real-IP headers.
Static file server. With UPSTREAM empty, Caddy serves files from /srv, which is handy for a landing page or a single-page app in a forked image.
Compression. Responses are compressed with gzip and zstd on the way out, even when the upstream app does not compress.
Private networking. Traffic between Caddy and your app stays on Railway's internal network, so the app itself needs no public domain.
Readable config. The Caddyfile is short and easy to change: add basic authentication, route /api and / to different services, or set security and cache headers.
Tiny footprint. Caddy is a single Go binary that idles at a few tens of megabytes of memory.
Deploy Caddy in Under 5 Minutes
- Click Deploy on Railway. No inputs are needed.
- Make sure your app listens on
::(IPv6 and IPv4) and note its private domain and port, for examplemyapp.railway.internaland3000. - On the
caddyservice, setUPSTREAMtomyapp.railway.internal:3000and redeploy. - Open Caddy's public URL and confirm your app answers. A 502 usually means a wrong port or an app that only listens on IPv4.
- Remove the public domain from the app service so only Caddy is exposed.
Common Use Cases
- Protect an internal dashboard: add basic auth in front of an admin tool that has no login of its own.
- One domain for frontend and API: route
/api/*to one service and everything else to another. - Security headers without code changes: add HSTS, cache and content headers to a third-party app.
- Compression for older apps: compress responses from an upstream that sends plain text.
- Gateway for several services: expose one public endpoint while every backend stays private.
- Static sites: serve a small static site or documentation build from
/srv. - Staging gates: keep preview environments behind a password before launch.
- Legacy apps: put an old app that only speaks HTTP on one port behind a modern front door.
- Webhook endpoints: expose only one path of an internal service to receive webhooks.
Configuration
| Variable | Required | Default | Description |
|---|---|---|---|
PORT | Required | 8080 | Port Caddy listens on; the public domain routes here |
UPSTREAM | Optional | empty | Private target as host:port; empty serves static files from /srv |
Finding the upstream address. Every Railway service has a private domain such as api.railway.internal. Use it with the port the app listens on, not the public domain.
IPv6 on the private network. Railway's private network uses IPv6. If Caddy returns a 502, make sure the upstream binds to :: or [::] rather than 0.0.0.0.
Advanced routing. Fork the template repository and edit the Caddyfile to use handle blocks for path routing, basic_auth with a hash from caddy hash-password, header for security headers, or several reverse_proxy targets with load balancing. Then deploy the service from your fork.
Custom domain. Add your domain to the caddy service in Railway. Railway issues the certificate and Caddy keeps serving plain HTTP behind it.
Health check. Railway checks / on Caddy. With an upstream set, that request passes through, so a down upstream marks Caddy unhealthy too.
Upgrades. Caddy 2.11.9 is out; change the image tag after testing to move to a newer release.
Logs. Caddy writes access and error logs to standard output, so they appear in the service's Railway logs. Use them to spot slow upstreams, 5xx errors or unexpected traffic.
Timeouts and large uploads. Caddy streams request bodies and keeps long connections such as WebSockets and server-sent events open by default, so chat apps and dashboards with live updates work without extra settings.
Example Caddyfile Recipes
Basic auth for an admin tool. Generate a hash with caddy hash-password, then wrap the proxy in a basic_auth block with a username and that hash. Every request must log in before it reaches the upstream.
Split frontend and API. Use handle /api/* with reverse_proxy api.railway.internal:8080 and a second handle block with reverse_proxy web.railway.internal:3000. Users see one domain and both services stay private.
Security headers. Add a header block with Strict-Transport-Security, X-Content-Type-Options nosniff and Referrer-Policy to harden any app.
Redirects. Use redir to send an old path or a bare domain to a new location with a permanent redirect.
Load balancing. List several upstreams after reverse_proxy and pick a policy such as round_robin or least_conn, with health checks to skip failed instances.
Maintenance page. Use handle_errors to show a friendly static page when the upstream is down.
Path stripping. Use handle_path /docs/* to serve a docs service under a subpath while the docs app itself sees requests at its root.
Rate of change. Each recipe is a few lines, and Caddy validates the whole file at startup, so a typo shows up in the deploy logs instead of breaking traffic silently.
Caddy vs. Alternatives
| Feature | Caddy on Railway | Nginx | Traefik | HAProxy |
|---|---|---|---|---|
| Hosting | Self-hosted | Self-hosted | Self-hosted | Self-hosted |
| License | Apache-2.0 | BSD-2-Clause | MIT | GPL-2.0 |
| Simple config file | ✅ | Verbose | Labels or YAML | Verbose |
| Reverse proxy | ✅ | ✅ | ✅ | ✅ |
| Static file serving | ✅ | ✅ | ❌ | ❌ |
| Compression built in | ✅ | ✅ | ✅ | ✅ |
| Price | A few dollars a month | Hosting cost | Hosting cost | Hosting cost |
Nginx is the classic choice with huge documentation. Traefik shines with Docker and Kubernetes discovery. HAProxy is a high-performance load balancer. Caddy is the quickest to configure for a single front door.
Dependencies for Caddy Hosting
- A Railway account.
- At least one private service to put behind the proxy, or static files to serve.
Deployment Dependencies
- Caddy on GitHub: source code and releases
- Caddy documentation: Caddyfile directives and examples
- Caddy Docker image: official image tags
Implementation Details
The Caddyfile listens on {$PORT}, enables gzip and zstd encoding, and either proxies to {$UPSTREAM} with forwarding headers or serves /srv. Railway's edge handles TLS, so Caddy's automatic HTTPS is not needed inside the container.
Frequently Asked Questions
What is Caddy? An Apache-2.0 open source web server and reverse proxy with a simple configuration file.
How much does it cost to host Caddy? Usually a few dollars a month on Railway, since Caddy uses very little memory and CPU.
How do I point Caddy at my app?
Set UPSTREAM to your app's private domain and port, such as myapp.railway.internal:3000, and redeploy.
Why do I get a 502 error?
The port is wrong or the app only listens on IPv4. Bind the app to ::.
Can I add a password?
Yes. Fork the template, add a basic_auth block to the Caddyfile, and deploy from your fork.
Do I need to manage TLS certificates? No. Railway terminates HTTPS at its edge, including for custom domains.
Why Deploy and Host Caddy 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 Caddy on Railway, you get a lightweight public front door for private services, with compression and simple routing, without managing servers or certificates.
Template Content