src/docs/markdown/quick-starts/static-files.md
This guide will show you how to get a production-ready static file server up and running quickly.
Prerequisites:
caddy in your PATHThere are two easy ways to get a quick file server up and running.
In your terminal, change to the root directory of your site and run:
<pre><code class="cmd bash">caddy file-server</code></pre>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:
<pre><code class="cmd bash">caddy file-server --listen :2015</code></pre>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:
You can use another folder as the site root:
<pre><code class="cmd bash">caddy file-server --root ~/mysite</code></pre>In the root of your site, create a file called Caddyfile with these contents:
localhost
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:
<pre><code class="cmd bash">caddy run</code></pre>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:
localhost
file_server browse
You can also use another folder as the site root:
localhost
root /var/www/mysite
file_server