Advanced Caddy Plugin Features

Previously, we talked about how to implement a simple Caddy plugin. In this post, we’ll talk about some of the more powerful features we can use. Registering New Types of Network Sometimes, we may want to securely expose a socket on a machine to a remote machine. We can set up an SSH tunnel to do so. The following example from the official documents shows how to set up an HTTP server this way. ...

published on March 10, 2024 · 4 min · 665 words

Writing a Caddy Plugin Part II

Previous post discusses the basics of a Caddy plugin and shows an example of a bare-bone plugin. In this post we implement a Caddy module that listens to a TCP socket and replies Hello world to every connected client. Plugin Considerations Before we begin, we need to think about what our plugin can do and how its behavior can be customized by its user. Depending on the function, the full configuration may be complex, but we should provide a reasonable default to the user. ...

published on January 22, 2024 · last edited on February 3, 2024 · 4 min · 816 words

Writing a Caddy Plugin Part I

Caddy is a server best known for its auto HTTPS features. It manages TLS certificates automatically without any human intervention. It’s also quite extensible, there are some built-in namespaces that define how we can implement some interfaces to add new functionalities to Caddy. First, let’s see how Caddy works. Caddy Architecture Caddy has three parts: a commandline interface, a core and module system. Command Interface It is how Caddy interprets commandline arguments to run some common tasks such as printing help information and running a simple reverse proxy or a file server. ...

published on January 8, 2024 · last edited on February 1, 2024 · 2 min · 382 words

Fixing Caddy's HTTP3

Caddy has supported http3 for a long time. First it’s an experimental feature, then in v2.6.0 it is on by default. There were some bugs, but I believe with the latest commits, most of them are gone. Problems Socket Reuse To improve efficiency, caddy tries to reuse sockets between configuration reloads. For Windows systems caddy has to wrap the underlying socket and set deadlines to terminate old use of the socket. For unix systems caddy applies the SO_REUSEPORT parameter when creating the socket. For counting the number of uses of the socket, caddy also wraps these sockets. ...

published on October 25, 2023 · 3 min · 629 words

Using Templates with Caddy and Hugo

Hugo is a static site generator. However sometimes we want to serve dynamic contents. We can embed javascript to achieve what we want, but why not use templates when they’re more convenient? Caddy Template Engine Caddy comes with a powerful template engine that is based on golang standard library. Some of the sites (including Caddy’s official website) are built this way. The list of template functions/actions can be viewed here. In addition, caddy also support all Sprig functions. ...

published on October 10, 2023 · 3 min · 472 words

Using jd to Manage Caddy Configuration

Caddy is a powerful, extensible server written in go. Though its native configuration format is json, it supports Caddyfile which is very easy to write. For the majority of use cases, caddy’s default configuration is enough. For power users, however, some configurations are not exposed in Caddyfile and must be set using json. Because caddy config uses json format, we can use tools that modify json to produce caddy config. ...

published on June 19, 2023 · 2 min · 369 words

HTTP3 Demo

This post first demonstrates http1, http2, http3 like akamai, then shows how the demo works. Demonstrations Info Firefox has a bug/feature that it will cache images even though instructed not to. Use another browser or hard refresh to rerun the tests. ...

published on May 17, 2023 · last edited on September 23, 2026 · 3 min · 522 words

Writing a Forward Auth for ttyd

Background ttyd is a simple tool for sharing terminal over the web. It can be used in place of ssh clients to manage remote servers as it only requires the presence of a browser with internet connectivity. It can be used with a variety of commands ranging from showing the output of top command to fully interactive bash session. However, ttyd itself only supports basic auth and auth proxy. In basic auth mode, ttyd authenticates requests from a predefined list of users. In auth proxy mode, ttyd will only authenticate clients with the specific http header. The first mode has the problem that users cannot be updated while ttyd is running. ttyd must be stopped and rerun with another set of users if users are to be updated. The second mode assumes ttyd is behind a reverse proxy and delegates authentication to the reverse proxy. If I’m using a reverse proxy to authenticate the request, then why check the header anyway? ...

published on February 28, 2023 · last edited on April 21, 2023 · 5 min · 940 words