Caddy (web server)
{{Short description|Open source web server}}
{{Multiple issues|
{{COI|date=May 2023}}
{{Primary sources|date=May 2023}}
{{Self-published|date=May 2023}}
}}
{{Infobox software
| name = Caddy
| logo = Caddyserver logo light.svg
| logo size = frameless
| author = Matthew Holt
| released = {{Start date and age|df=yes|2015|4|28}}
| latest release version = {{wikidata|property|preferred|references|edit|P348|P548=Q2804309}}
| latest release date = {{Start date and age|{{wikidata|qualifier|preferred|single|P348|P548=Q2804309|P577}}|df=yes}}
| programming language = Go{{ cite web | url = https://blog.golang.org/go1.6 | title = Go 1.6 is released | first = Andrew | last = Gerrand | website = golang.org | date = 17 February 2016 | access-date = 5 March 2016 }}
| repo = {{URL|https://github.com/caddyserver/caddy}}
| operating system = BSD variants, Linux, Plan 9, macOS and Windows
| platform = IA-32 (i386), x86-64, ARM, MIPS, S390X
| genre = Web server, reverse proxy server
| license = Apache 2
| website = {{Official URL}}
}}
Caddy is an extensible, cross-platform, open-source web server written in Go.
The name "Caddy" refers both to a helper for tedious tasks, and a way to organize multiple parts into a simplified system.{{Citation|title=README.md|date=2021-09-27|url=https://github.com/caddyserver/caddy/blob/059fc32f002d00e980b438b3edbdf7b8bcdf9a90/README.md|publisher=caddyserver/caddy on GitHub|access-date=2021-09-27}} At its core, Caddy is an extensible platform for deploying long-running services ("apps") using a single, unified configuration that can be updated on-line with a REST API.{{Cite web|last=|first=|title=Welcome - Caddy Documentation|url=https://caddyserver.com/docs/|url-status=live|access-date=2021-09-27|website=caddyserver.com|archive-url=https://web.archive.org/web/20150502021831/http://caddyserver.com:80/docs |archive-date=2015-05-02 }} Official Caddy distributions ship with a set of standard modules which include HTTP server, TLS automation, and PKI apps.{{Citation|title=imports.go|date=2021-09-27|url=https://github.com/caddyserver/caddy/blob/059fc32f002d00e980b438b3edbdf7b8bcdf9a90/modules/standard/imports.go|publisher=caddyserver/caddy on GitHub|access-date=2021-09-27}} It is best known for its automatic HTTPS features.{{Cite book|last=Woodbeck|first=Adam|url=https://www.worldcat.org/oclc/1198449668|title=Network programming with GO : code secure and reliable network services from Scratch|date=2021|isbn=978-1-7185-0088-4|location=San Francisco, CA|pages=217–239|oclc=1198449668}}{{Cite web |title=Caddy offers TLS, HTTPS, and more in one dependency-free Go Web server |author=Jim Salter |work=Ars Technica |date=May 6, 2020 |access-date=June 12, 2023 |url= https://arstechnica.com/gadgets/2020/05/caddy-offers-tls-https-and-more-in-one-dependency-free-go-web-server/ }}
Architecture
Caddy is organized into three main components: a command, the core library, and configuration modules.{{Cite web|last=|first=|title=Architecture - Caddy Documentation|url=https://caddyserver.com/docs/architecture|url-status=live|access-date=2021-09-27|website=caddyserver.com|archive-url=https://web.archive.org/web/20200414211535/https://caddyserver.com/docs/architecture |archive-date=2020-04-14 }} The command is the extensible interface by which the program is executed; it can also load configuration files, run common modes, manage installed plugins, and offer relevant utility functions. The core library has APIs for loading, unloading, and managing configuration; but it does nothing particularly useful on its own. Most of Caddy's functionality is provided by modules, which are plugins that extend Caddy's configuration structure; for example, the HTTP server is a module.{{Cite web|last=|first=|title=Module http - Caddy Documentation|url=https://caddyserver.com/docs/modules/http|url-status=live|access-date=2021-09-27|website=caddyserver.com|archive-url=https://web.archive.org/web/20200506180231/https://caddyserver.com/docs/modules/http |archive-date=2020-05-06 }} Caddy modules implement various long-running services, web standards, and other useful features.
Caddy's input is a JSON configuration document{{Cite web|last=|first=|title=JSON Config Structure - Caddy Documentation|url=https://caddyserver.com/docs/json/|url-status=live|access-date=2021-09-27|website=caddyserver.com|archive-url=https://web.archive.org/web/20200414211537/https://caddyserver.com/docs/json/ |archive-date=2020-04-14 }} which is received through an open socket via a RESTful HTTP API.{{Cite web|last=|first=|title=API - Caddy Documentation|url=https://caddyserver.com/docs/api|url-status=live|access-date=2021-09-27|website=caddyserver.com|archive-url=https://web.archive.org/web/20200302140614/https://caddyserver.com/docs/api |archive-date=2020-03-02 }} In the absence of an HTTP client, Caddy's command-line interface can be used to load configuration files.{{Cite web|last=|first=|title=Command Line - Caddy Documentation|url=https://caddyserver.com/docs/command-line|url-status=live|access-date=2021-09-27|website=caddyserver.com|archive-url=https://web.archive.org/web/20200302140614/https://caddyserver.com/docs/command-line |archive-date=2020-03-02 }} Config adapters may be used to convert other configuration formats to JSON. Existing adapters include the Caddyfile, which has first-class support in the command line; and YAML, TOML, Nginx, and several other formats.{{Cite web|last=|first=|title=Config Adapters - Caddy Documentation|url=https://caddyserver.com/docs/config-adapters|url-status=live|access-date=2021-09-27|website=caddyserver.com|archive-url=https://web.archive.org/web/20200414211537/https://caddyserver.com/docs/config-adapters |archive-date=2020-04-14 }}
When a configuration is received through its administration socket, Caddy decodes the configuration for all the specified modules, and starts running all the app modules. When the app modules are being provisioned, they themselves may load and provision modules that they use. For example, the HTTP server is an app module which uses HTTP handler modules to handle HTTP requests; these handlers might use yet other modules to implement their functionality, and so on.{{Citation|last=Holt|first=Matthew|title=The Engineering Challenges of long running go programs|date=2019-12-04|url=https://www.youtube.com/watch?v=EhJO8giOqQs|publisher=Forge Utah|language=en|access-date=2021-09-27}} All these modules are provisioned during the config load phase.
Plugins are installed by statically compiling them directly into the Caddy binary. Without plugins, Caddy's native configuration structure only has some basic options for administration and logging. All other functionality must be provided by app modules. Official Caddy distributions ship with dozens of standard modules; others can be added from the project's website,{{Cite web|last=|first=|title=Download Caddy|url=https://caddyserver.com/download|url-status=live|access-date=2021-09-27|website=caddyserver.com|archive-url=https://web.archive.org/web/20150502021904/http://caddyserver.com:80/download |archive-date=2015-05-02 }} using the xcaddy
command line tool, or by manually compiling a custom build.{{Cite web |last= |first= |title=Build from source - Caddy Documentation |url=https://caddyserver.com/docs/build#cross-platform |url-status=live |archive-url=https://web.archive.org/web/20200529135850/https://caddyserver.com/docs/build |archive-date=2020-05-29 |access-date=2021-09-27 |website=caddyserver.com}}
HTTP server
The HTTP server is an app module that comes standard with official Caddy distributions. It is primarily used as a static file server{{Cite web|last=|first=|title=Static files quick-start - Caddy Documentation|url=https://caddyserver.com/docs/quick-starts/static-files|url-status=live|access-date=2021-09-27|website=caddyserver.com|archive-url=https://web.archive.org/web/20200508161234/https://caddyserver.com/docs/quick-starts/static-files |archive-date=2020-05-08 }} and load-balancing reverse proxy.{{Cite web|last=|first=|title=Reverse proxy quick-start - Caddy Documentation|url=https://caddyserver.com/docs/quick-starts/reverse-proxy|url-status=live|access-date=2021-09-27|website=caddyserver.com|archive-url=https://web.archive.org/web/20200508142045/https://caddyserver.com/docs/quick-starts/reverse-proxy |archive-date=2020-05-08 }} While the basis of Caddy's HTTP features use the implementation found in Go's standard library,{{Cite web|last=Holt|first=Matthew|date=2015-05-27|title=A Look Inside Caddy, a Web Server Written in Go|url=https://blog.gopheracademy.com/caddy-a-look-inside/|url-status=live|access-date=2021-09-27|website=blog.gopheracademy.com|language=en-us|archive-url=https://web.archive.org/web/20150530042315/http://blog.gopheracademy.com:80/caddy-a-look-inside/ |archive-date=2015-05-30 }} a variety enhancements and customizations are available as middleware and exposed through configuration parameters:
By default, TLS is used automatically if any routes have a non-empty host matcher.{{Cite web|last=|first=|title=Automatic HTTPS - Caddy Documentation|url=https://caddyserver.com/docs/automatic-https|url-status=live|access-date=2021-09-27|website=caddyserver.com|archive-url=https://web.archive.org/web/20160304045646/https://caddyserver.com/docs/automatic-https |archive-date=2016-03-04 }} These are assumed to be site names or IP addresses that Caddy is serving, so Caddy will automatically procure and renew certificates for the configured hostnames and IP addresses. When automatic HTTPS is activated in this manner, Caddy will also redirect HTTP requests to their equivalent HTTPS location.
Development
Caddy version 2 was released on May 5, 2020. Reviewers say that it still has a simpler configuration file syntax than the Apache Web Server, although version 2's configuration format is largely incompatible with the previous major release of Caddy.{{Cite web |title=How to deploy a single web page to the Caddy server from a Caddyfile |author=Jack Wallen |work=TechRepublic |date=May 26, 2022 |access-date=12 June 2023 |url= https://www.techrepublic.com/article/deploy-web-caddy-server-caddyfile/ }}
Derivatives
References
{{Reflist}}