Caddy HTTP server

Caddy is a powerful, enterprise-ready, open source web server with automatic HTTPS written in Go.

To install caddy, first add the caddy program to your gokrazy instance:

gok add github.com/caddyserver/caddy/v2/cmd/caddy

Then, open your instance’s config.json in your editor:

gok edit

And make the following changes:

  1. Change the HTTP port from 80 (default) to 1080 (for example) to move gokrazy’s web interface listening port out of the way and let caddy serve on TCP port 80. If you want to run caddy on a different port, you can skip this step.
  2. Configure Package config: Command-line flags and Package config: Extra files to make caddy run its webserver on startup (run) and to make caddy locate its config file (--config).
{
    "Hostname": "webserver",
    "Update": {
        "HTTPPort": "1080"
    },
    "Packages": [
        "github.com/gokrazy/fbstatus",
        "github.com/gokrazy/hello",
        "github.com/gokrazy/serial-busybox",
        "github.com/gokrazy/breakglass",
        "github.com/caddyserver/caddy/v2/cmd/caddy"
    ],
    "PackageConfig": {
        "github.com/caddyserver/caddy/v2/cmd/caddy": {
            "CommandLineFlags": [
                "run",
                "--config",
                "/etc/caddy/Caddyfile"
            ],
            "ExtraFilePaths": {
                "/etc/caddy/Caddyfile": "Caddyfile"
            }
        }
    }
}

Then, create the referenced Caddyfile extra file and modify it to your liking. In this example, we explicitly configure an HTTP listener to disable Caddy’s automatic HTTPS setup, so that your server will work without a publically reachable address.

cat > ~/gokrazy/webserver/Caddyfile <<'EOT'
http://:80 {
	root * /tmp
	file_server browse 
}
EOT

Then, deploy as usual:

gok update

Tip: When using breakglass, use the -gokrazy_url=:1080 flag to overwrite the port.