Static files quick-start

This guide will show you how to get a production-ready static file server up and running quickly.

Prerequisites:

  • Basic terminal / command line skills
  • caddy in your PATH
  • A folder containing your website

There are two easy ways to get a quick file server up and running. We’ll show you two equivalent ways to do the same thing.

Command line

In your terminal, change to the root directory of your site and run:

  1. caddy file-server

If you get a permissions error, it probably means your OS does not allow you to bind to low ports — so use a high port instead:

  1. caddy file-server --listen :2015

Then open localhost (or localhost:2015) in your browser to see your site!

If you don’t have an index file but you want to display a file listing, use the --browse option:

  1. caddy file-server --browse

You can use another folder as the site root:

  1. caddy file-server --root ~/mysite

Caddyfile

In the root of your site, create a file called Caddyfile with these contents:

  1. localhost
  2. file_server

If you don’t have permission to bind to low ports, replace localhost with localhost:2015 (or some other high port).

Then, from the same directory, run:

  1. caddy run

You can then load localhost (or whatever the address is in your config) to see your site!

The file_server directive has more options for you to customize your site. Make sure to reload Caddy (or stop and start it again) when you change the Caddyfile!

If you don’t have an index file but you want to display a file listing, use the browse argument:

  1. localhost
  2. file_server browse

You can also use another folder as the site root:

  1. localhost
  2. root * /home/me/mysite
  3. file_server