---
title: "Deploy Deploy Caddy Static File Server"
description: "Serve and browse files over HTTPS with Caddy file_server"
category: "Starters"
url: https://railway.com/deploy/deploy-caddy-static-file-server
---

# Deploy Deploy Caddy Static File Server

Serve and browse files over HTTPS with Caddy file_server

**[Deploy Deploy Caddy Static File Server on Railway](https://railway.com/template/deploy-caddy-static-file-server)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/deploy-caddy-static-file-server/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 File Server (Self-Hosted File Server With Caddy) on Railway

This template runs Caddy as a file server on Railway, serving a site root with file_server so you can publish downloads with directory listings or host a private share.

## About Hosting Caddy File Server open-source software on Railway (self hosted Caddy file_server for serving downloads template)

This template runs the official Caddy 2.11.7 image as one service called caddy.

Your files and config stay in your own Railway project. Railway handles the build, runtime, and PORT injection.

## Why Deploy Caddy File Server, the Nginx alternative on Railway (Railway Free Trial)

Nginx is a fine choice, but for a file share it asks you to write and maintain a server config for directory listings, precompressed assets, and password protection on one path.

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 File Server 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 File Server self hosting

Railway trades server control for setup speed when you run a Caddy file share. Here is how it compares with a raw VPS.

| Provider | What You Get with Railway | What You Get with the Other Provider |
| --- | --- | --- |
| DigitalOcean | Caddy deploys with zero inputs, edge TLS is handled, and custom domains go through Railway networking. | A full Linux droplet where you install Caddy, manage systemd, and handle firewall and certificates. |
| AWS | One Caddy service with usage billing and no VPC or IAM setup for a basic file share. | Deep networking and storage control, but you wire up EC2, EBS, and load balancing first. |
| Hetzner | Caddy runs in a managed container with the Caddyfile in place, so no OS patching. | Low-cost servers with generous bandwidth, but you maintain the box and every Caddy upgrade. |

A VPS suits teams that need host-level control, while Railway saves time on a small download share.

## Common Use Cases for hosted Caddy File Server

- **Publishing release binaries:** Point `root` at a folder of builds and add `file_server browse` so testers can click through versions. Sort newest first with `sort namedirfirst desc`.
- **Serving precompressed assets:** Ship `.br` and `.gz` sidecar files and add `precompressed` so clients get the smaller copy when they accept it. Uncompressed files are still checked first, so old clients keep working.
- **Sharing build artifacts privately:** Wrap `/private/*` in `basic_auth` and keep the rest public. Hash the password with `caddy hash-password` first, and only do this over HTTPS.
- **Local file serving during development:** Run `caddy file-server --browse` in any folder for an instant listing with no Caddyfile. Add `--listen :2015` if low ports give permission errors.
- **Read-only dataset mirror:** Serve a static dataset and use `hide` with glob patterns to keep files like `*.env` out of listings. It is a convenience filter, not a security boundary.

## Dependencies for Caddy File Server Docker hosted on Railway

The stack is one service called `caddy`, built on the official Caddy 2.11.7 image, with no deploy-time inputs and no secrets.

### Deployment Dependencies for Managed Caddy File Server Service (Web Server)

You need a Railway account, plus GitHub if you plan to commit your own files. There is no database or cache to provision.

### Implementation Details for Caddy File Server (Using Caddy official docker image)

The image is `ghcr.io/onepush-dev/caddy:2.11.7`, which wraps the official `caddy:2.11.7-alpine` image pinned by digest.

## How does Caddy File Server compare against other ways to serve downloadable files from a self-hosted web server

### Caddy File Server vs Nginx (Nginx Alternative)

- **Config style:** A root, file_server, and a basic_auth matcher on one path fit in about six Caddyfile lines. Nginx needs separate autoindex, auth_basic, and location blocks.
- **Precompressed files:** Caddy serves .br and .gz sidecar files without extra modules. Nginx needs gzip_static or brotli_static set up on purpose.
- **Where Nginx wins:** It has a longer track record, more tuning knobs for high concurrency, and far more examples online.

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

- **Setup effort:** Caddy needs no .htaccess file for browse listings. Apache's Options Indexes and per-directory auth often live in .htaccess or VirtualHost blocks you must keep in sync.
- **Hiding files:** Caddy's hide directive filters by path pattern, but matching is case-sensitive, so don't treat it as a security boundary.
- **Where Apache wins:** Its module ecosystem is huge, and legacy .htaccess setups are hard to leave.

### Caddy File Server vs Netlify (Netlify Alternative)

- **Where files live:** Netlify deploys from Git, while Caddy serves whatever sits in /srv on your own Railway service. Caddy's basic_auth covers a private download directly.
- **Control:** You own the Caddyfile and headers behind Railway networking.
- **Where Netlify wins:** Deploy previews, a global CDN, and no server upkeep. For public downloads published by Git push, it is simpler.

### Caddy File Server vs Cloudflare Pages (Cloudflare Pages Alternative)

- **Deploy model:** Cloudflare Pages builds from Git and serves static output at the edge. Caddy serves a directory you control, including files uploaded to a volume at runtime.
- **Auth on a path:** A basic_auth matcher is one Caddyfile block. Pages needs Cloudflare Access or a Worker for the same job.
- **Where Cloudflare Pages wins:** Edge caching across many regions and a free tier that covers many small sites with no server to manage.

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

1. Deploy the `caddy` service from the Railway template and confirm it serves `/srv` (repo `www/`) with a 200 response on the public URL.
2. For a private share where you upload at runtime, add a volume at `/srv` so files survive redeploys.
3. Generate a password hash with `caddy hash-password`. Keep plaintext passwords out of the Caddyfile.
4. Edit the Caddyfile so `basic_auth /private/*` comes before `file_server browse`, both under the site-level `root`.
5. Set your custom domain through Railway networking and keep `auto_https off` inside the container.
6. Confirm that a request to `/private` without credentials returns 401 Unauthorized.

```
{
	admin off
	auto_https off
}

:{$PORT:8080} {
	root * /srv
	encode gzip zstd

	basic_auth /private/* {
		alice 
	}

	file_server browse {
		hide .env *.bak
	}
}
```

```
caddy hash-password --plaintext 'your-long-passphrase'
```

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

This walkthrough runs the same Caddyfile on a plain Linux VPS if you want full control of the box. Railway handles all of this for you on its platform.

### Clone the Repository

Grab the project and move into it. Static files live in `www/`, which maps to `/srv` in the container.

```bash
git clone https://github.com/your-org/caddy-file-server.git
cd caddy-file-server
```

### Install Dependencies

Install Caddy from the official package repository. Avoid keeping your share under `/home`, because the `caddy` user cannot traverse it.

```bash
sudo apt install -y caddy
caddy version
```

### Configure Environment Variables

Set `PORT` for the listen port and leave `UPSTREAM` empty for static file mode. Copy the share into `/srv`.

```bash
export PORT=8080
export UPSTREAM=
sudo mkdir -p /srv &amp;&amp; sudo cp -r www/. /srv/
```

### Start the Caddy File Server Application

Run Caddy against the repo Caddyfile, then check that your-domain returns the listing you expect.

```bash
caddy run --config Caddyfile --adapter caddyfile
curl -I http://your-domain:8080/
```

Railway takes care of the runtime, the public URL, and TLS at its edge.

## Official Pricing of Caddy File Server (Caddy pricing)

Caddy is free and open source under the Apache-2.0 license, so there is no license fee to pay for the file server itself.

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

A managed file share and a self-hosted one do the same job, since file_server handles both. Here is how the two paths compare.

### Monthly cost of self hosting Caddy File Server on Railway

On Railway you pay for usage rather than a fixed server. Heavy downloads cost more because egress and CPU climb with traffic.

### System Requirements for Hosting Caddy File Server on a VPS

Caddy is a single static binary, so the hardware bar is low. Disk is the real requirement, since your files live there.

## Frequently Asked Questions (FAQs)

### How do I turn on directory listings with browse?

Add `browse` inside `file_server`, as in `file_server browse`. Listings only appear for folders with no index file such as `index.html`.

### Why does systemd-run Caddy fail to read files in /home?

The `caddy` user lacks traversal permission on `/home`, so the server cannot reach files there.

### How do I hide files like .env with hide?

Use `hide` with a file system path or glob, such as `hide /srv/.env*`, and repeat it for each pattern.

### Is basic_auth safe without HTTPS?

No. Put the share behind HTTPS through Railway networking before relying on it.

### How do precompressed .br and .gz files get served?

Add `precompressed` to `file_server` and place sidecar files like `app.js.br` or `app.js.gz` beside the originals.

### How do I protect only one path instead of the whole site?

Put a matcher on `basic_auth`, such as `basic_auth /private/* { user HASHED_PASSWORD }`, and keep `file_server` after it.


## 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/deploy-caddy-static-file-server
