Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Caddy

From Nest Guides
Revision as of 03:48, 21 February 2024 by Samuel (talk | contribs) (Create basic Caddy page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Caddy is a webserver - that is, it's a program that'll serve your website (and any other web resource, such as an API) for all to see! It's also the default and recommended webserver to use on Nest.

By default, you have a Caddy configuration file (Caddyfile) in your home directory, and a directory called pub inside your home directory as well that contains an index.html file. The Caddyfile contains a minimal setup for serving files from the pub directory. Your Caddy server is always running, so you don't need to worry about starting it up.

Let's take a look at the default Caddyfile to understand how Caddy works:

{
  admin off
}

http://<username>.hackclub.app {
  bind unix/.webserver.sock|777
  root * /home/<username>/pub
  file_server
}

The first 3 lines, containing the admin off line, are part of the global configuration of Caddy. admin off just tells Caddy to disable the admin API, which is a cool feature that allows you to dynamically access and modify configuration, but that we won't be using.

What comes next is the configuration for our subdomain, <username>.hackclub.app (<username> will be replaced with your Nest username). You might notice that it specifies http instead of https. This is because there's actually another "root" Caddy server that in turn proxies the request to your Caddy server, and it needs your server to use http. It proxies that request through your webserver's socket, which is specified on the next line. You can even see this socket in your home directory if you run ls!

Next up is the line that starts with root. This line just tells Caddy what directory your website/files are in. Finally, the file_server line tells Caddy to just statically serve files directly from that directory!

Caddy is very powerful and has a ton of more features, but this is enough for you to get a simple website running. You can explore all of Caddy's features in their docs at https://caddyserver.com/docs/.