---
title: "Deploy Caddy"
description: "Caddy 2.11 static site or reverse proxy"
category: "Starters"
url: https://railway.com/deploy/caddy-1
---

# Deploy Caddy

Caddy 2.11 static site or reverse proxy

**[Deploy Caddy on Railway](https://railway.com/template/caddy-1)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/caddy-1/manifest.json

- **Creator:** onepush
- **Category:** Starters

## Template content

### caddy https://github.com/caddyserver.png

- **Image:** ghcr.io/onepush-dev/caddy:2.11.7
- **Health check:** /
- **Public domain:** Yes

## Documentation

# Deploy and Host self hosted Caddy (Open-Source Web Server & Reverse Proxy) on Railway

Caddy 2.11.7 on the official Alpine image gives you a web server that either serves static files from /srv or reverse-proxies a private Railway service when you set UPSTREAM.

## About Hosting Caddy open-source software on Railway (self hosted Caddy template)

This template runs the official Caddy 2.11.7 Alpine image through the onepush-dev wrapper as one Railway service named caddy. By default it serves static files from /srv, filled from the repo's www/ directory.

## Why Deploy Caddy, the Nginx / Traefik alternative on Railway (Railway Free Trial)

Caddy on Railway saves you the VPS chores of patching a box, managing certificates, and hand-tuning Nginx configs. Railway's $5 free trial is enough to test a static site or one UPSTREAM proxy before you commit.

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 are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

### Railway vs Other Hosting Providers and VPS for Caddy self hosting

Railway runs Caddy as one service with no server, OS, or TLS setup on your side, since its edge handles HTTPS for the public URL. The table compares the tradeoffs.

| Provider | What You Get with Railway | What You Get with the Other Provider |
| --- | --- | --- |
| DigitalOcean | A Caddy service from the template with no inputs and Railway edge TLS. | A Droplet with root access, your own Caddy install, and certificate handling. |
| AWS | One service with no IAM, VPC, or load balancer setup. | Full EC2 and networking control, but security groups and Caddy are yours to configure. |
| Hetzner | Deploys in minutes with no server sizing or SSH keys. | Low-cost hardware, but you install Caddy, patch updates, and manage backups. |

## Common Use Cases for hosted Caddy

- **Static site from /srv:** Drop built HTML, CSS, and assets into the repo's www/ folder and Caddy serves them with no config changes.
- **SPA fallback:** The default Caddyfile uses try_files {path} /index.html, so deep links return your index.html instead of a 404.
- **Front door for a private service:** Set UPSTREAM to host:port on the Railway private network and Caddy switches to reverse-proxy mode without file edits.
- **Compressed edge:** The encode gzip zstd directive compresses responses on the way out, cutting bandwidth to a slow origin.
- **Replacing a DIY VPS:** It covers the job of a hand-maintained Nginx or Caddy server without the OS patching or certificate chores.

## Dependencies for Caddy Docker hosted on Railway

This section covers what you need before you deploy and what the template runs once it is live.

### Deployment Dependencies for Managed Caddy Service (Static or Proxy)

You need a Railway account and a GitHub account that Railway can read, since the template pulls from the onepush-dev/caddy repository. There are no required deploy-time variables and no secrets.

### Implementation Details for Caddy (Using official caddy 2.11.7-alpine via onepush-dev image)

The service runs ghcr.io/onepush-dev/caddy:2.11.7, which wraps the official caddy:2.11.7-alpine base pinned by digest sha256:eb4d35b7452d1ab6171fbdbe8d9275b2301dad6dad92115d91e19fb9b24d510f.

## How does Caddy compare against other reverse proxy and web server platforms

### Caddy vs Nginx (Nginx Alternative)

- **Config model:** Caddy's Caddyfile is short, and this template needs no edits to switch between static files and proxying. Nginx offers finer control over buffers and timeouts.
- **Automatic TLS:** Caddy can manage certificates itself, but this Railway setup uses auto_https off because Railway's edge handles TLS. Nginx needs certbot or similar wired in by hand.
- **Ecosystem:** Nginx has decades of modules and distro packages. Caddy's plugins need xcaddy and a custom build, which this template does not use.

### Caddy vs Traefik (Traefik Alternative)

- **Discovery:** Traefik watches Docker or Kubernetes and routes automatically as services appear. Caddy here uses one UPSTREAM variable pointing at a fixed host:port, which is simpler but less dynamic.
- **Dashboard and middleware:** Traefik ships a dashboard and a large middleware catalog. Caddy keeps the stock image small.
- **Fit:** Choose Traefik for many services that come and go. For one static site or a single private backend, Caddy is usually less to maintain.

### Caddy vs HAProxy (HAProxy Alternative)

- **Load balancing depth:** HAProxy offers advanced balancing, health checks, and connection tuning that Caddy's basic reverse_proxy does not match.
- **Serving files:** Caddy serves static sites from /srv with try_files fallback out of the box. HAProxy is a proxy and does not serve files.
- **Operational weight:** HAProxy is very fast in high-traffic setups. Caddy is lighter to reason about for a small front door on Railway.

### Caddy vs Apache httpd (Apache httpd Alternative)

- **Configuration:** Apache relies on .htaccess and a long module list. Caddy's Caddyfile is far shorter for common static and proxy cases.
- **Compression and defaults:** Caddy enables gzip and zstd here with no extra setup. Apache needs mod_deflate or mod_brotli configured.
- **Legacy support:** Apache wins where you depend on older modules or heavy .htaccess workflows. For a clean container deployment, Caddy asks for less.

## How to use Caddy (the OSS web server and reverse proxy)?

1. Deploy the template with no inputs. PORT is injected by Railway, and UPSTREAM is optional and empty by default.
2. Open the public URL. A 200 response with the title "Caddy on Railway" means the default welcome page from www/ is live.
3. To serve your own static site, replace the files in www/ and redeploy. For runtime uploads, attach a volume at /srv instead.
4. To reverse-proxy another service, set UPSTREAM to its private domain and port, such as api.railway.internal:8080. That upstream must listen on IPv6 (::).
5. Railway's edge handles TLS. The container serves plain HTTP with auto_https off, so don't add 443 listeners or ACME config.

```
# UPSTREAM unset: static mode serves /srv
# UPSTREAM=api.railway.internal:8080: proxy mode
reverse_proxy {$UPSTREAM} {
    header_up X-Forwarded-Proto {scheme}
    header_up X-Real-IP {remote_host}
}
```

## How to self host Caddy on other VPS Services (Caddy self hosting guide)

If you'd rather run Caddy on a plain VPS, the steps below mirror what the Railway template does. The image is the official caddy:2.11.7-alpine build, so you can follow the upstream docs for anything not covered here.

### Clone the Repository

Grab the template source so you have the static files and Caddyfile to work from.

```bash
git clone https://github.com/onepush-dev/caddy.git
cd caddy
```

### Install Dependencies

Install Docker on your VPS. Caddy runs fine as a container, and you don't need a separate build step because the stock binary has no plugins to compile.

```bash
docker pull caddy:2.11.7-alpine
```

### Configure Environment Variables

Set PORT to the port Caddy should bind inside the container. Leave it empty to serve static files from /srv.

### Start the Caddy Application

Run the container with the port mapped and your files mounted, then check the response.

```bash
docker run -d -p 80:8080 -e PORT=8080 \
  -v "$PWD/www:/srv" caddy:2.11.7-alpine
```

Railway handles TLS at its edge and injects PORT for you, but on your own VPS you need to put a certificate in front of Caddy yourself.

## Official Pricing of Caddy (Caddy pricing)

Caddy itself is free and open source under the Apache-2.0 license, so there is no license fee to pay for the web server or reverse proxy. What you actually pay for is the infrastructure it runs on.

## Caddy cloud vs self hosted comparison (Pricing, features, costs, and more)

Running Caddy on Railway or on your own VPS comes down to infrastructure cost and the time you spend managing it. Check current Railway usage rates before you commit to either path.

### Monthly cost of self hosting Caddy on Railway

Railway bills by resource usage, so one small Caddy service costs whatever its CPU, memory, and egress add up to each month.

### System Requirements for Hosting Caddy on a VPS

On a VPS you need a Linux host with Docker or a Caddy binary, a public IP, and DNS pointed at it. You also own patching, backups, and renewal monitoring.

## Frequently Asked Questions (FAQs)

### When should I use static mode versus UPSTREAM mode?

Leave UPSTREAM empty to serve files from /srv, which is the repo's www/ directory by default. Set UPSTREAM to a host:port on Railway's private network to forward requests to another service instead.

### Why is auto_https turned off?

Railway's edge already terminates TLS for your public domain, so Caddy doesn't need to fetch certificates or listen on 443 inside the container.

### Where does the PORT value come from?

Railway injects PORT automatically, and Caddy binds to :{$PORT} to match it. Locally it falls back to 8080, so you don't need to set it yourself.

### Can I use a custom domain on Railway?

Yes. Add the domain in Railway's networking settings and Railway handles the certificate at the edge, while Caddy keeps serving plain HTTP on the injected port.

### Can I add plugins or build a custom binary with xcaddy?

Not with this template. It runs the stock official Caddy 2.11.7 Alpine binary with no extra modules, so for plugins you'll need your own image built with xcaddy.

### When is this stock binary the wrong choice?

Skip it if you need modules outside the official build, if you want Caddy managing certificates on its own ports, or if you rely on the admin API, which is switched off here.


## Similar templates

- [Openfront Gym](https://railway.com/deploy/openfront-gym) — Opensource Mindbody alternative based on Next.js and Keystone.js
- [open-excalidraw](https://railway.com/deploy/open-excalidraw) — Self-hostable collaborative drawing built on Excalidraw
- [Next.js + Prisma + PostgreSQL Starter](https://railway.com/deploy/nextjs-prisma-postgres) — Deploy a Next.js app with Prisma ORM and PostgreSQL in one click.

Open this page in a browser: https://railway.com/deploy/caddy-1
