Caddy: Difference between revisions

From ArchWiki
(Update Interlanguage link)
m (missing "-" in `caddy run --config`)
 
(16 intermediate revisions by 8 users not shown)
Line 2: Line 2:
[[ja:Caddy]]
[[ja:Caddy]]
[[zh-hans:Caddy]]
[[zh-hans:Caddy]]
[https://caddyserver.com/ Caddy] is a HTTP/2 capable web server with automatic HTTPS.
[https://caddyserver.com/ Caddy] is a HTTP/2 capable [[web server]] with automatic HTTPS.


== Installation ==
== Installation ==


[[Install]] the {{Pkg|caddy}} package.
[[Install]] the {{Pkg|caddy}} package.
== Plugins ==
If you need more than the base version of caddy, you can use {{AUR|xcaddy-bin}} to customize your caddy server build. This is useful if you need the additional plugins for DNS challenge, etc.
Alternatively, if a pre-built package, with the plugins you require, is already available you may choose to install those from [https://aur.archlinux.org/packages/?O=0&K=caddy AUR], for eg. {{AUR|caddy-cloudflare}}.
For a custom caddy server build you can use xcaddy to build caddy with the necessary plugin modules:
$ xcaddy build [<caddy_version>]
    [--output <file>]
    [--with <module[@version][=replacement]>...]
For more information, see the [https://github.com/caddyserver/xcaddy xcaddy repository].


== Configuration ==
== Configuration ==


Caddy is configured using a plain text file called {{ic|Caddyfile}}. The {{ic|Caddyfile}} starts with address of the site to be served, and is followed by a number of directives.
Caddy 2 supports various configuration formats, see [https://caddyserver.com/docs/config-adapters config adapters] (caddyfile, [[nginx]], json, yaml, toml, among others).
 
Most commonly, Caddy is configured using a plain text file called [https://caddyserver.com/docs/caddyfile Caddyfile]. The {{ic|Caddyfile}} starts with (an optional [https://caddyserver.com/docs/caddyfile/options global options block] and) an address of the site to be served, and is followed by a number of directives.


A simple {{ic|Caddyfile}} hosting the site at {{ic|localhost:2020}} using gzip compression and logging to {{ic|../access.log}}:
A simple {{ic|Caddyfile}} hosting the site at {{ic|localhost:2020}}:


{
  http_port 2020
}
  localhost:2020
  localhost:2020
  gzip
  file_server
log ../access.log
A more comprehensive example that would get you an A+ rating on https://securityheaders.com is https://gist.github.com/Strykar/e5c0e32ef21f3d9f04eab3e42349f9d0


== Usage ==
== Usage ==
$ caddy help
$ caddy help run


Caddy can be run by any user from the page's directory, and the {{ic|Caddyfile}} should be in the same directory:
Caddy can be run by any user from the page's directory, and the {{ic|Caddyfile}} should be in the same directory:


  $ caddy
  $ caddy run


Alternatively you may specify a custom {{ic|Caddyfile}}:
Alternatively you may specify a custom {{ic|Caddyfile}}:


  $ caddy -conf="../path/to/Caddyfile"
  $ caddy run --config ../path/to/Caddyfile
 
== Troubleshooting ==
 
=== Certificate error ===
 
If you are facing any issues related to SSL certificates (especially on non-public domains), it is probably because the running caddy instance does not have permission to add the certificate to the system's trust store. This seems to be the case when {{ic|caddy.service}} is used to autostart caddy.
 
To fix this, run the following as root. You only have to run this once in a very long time (lifetime of the root certificate).
 
# XDG_DATA_HOME=/var/lib caddy trust


== See also ==
== See also ==

Latest revision as of 22:30, 24 March 2024

Caddy is a HTTP/2 capable web server with automatic HTTPS.

Installation

Install the caddy package.

Plugins

If you need more than the base version of caddy, you can use xcaddy-binAUR to customize your caddy server build. This is useful if you need the additional plugins for DNS challenge, etc. Alternatively, if a pre-built package, with the plugins you require, is already available you may choose to install those from AUR, for eg. caddy-cloudflareAUR.

For a custom caddy server build you can use xcaddy to build caddy with the necessary plugin modules:

$ xcaddy build [<caddy_version>]
   [--output <file>]
   [--with <module[@version][=replacement]>...]

For more information, see the xcaddy repository.

Configuration

Caddy 2 supports various configuration formats, see config adapters (caddyfile, nginx, json, yaml, toml, among others).

Most commonly, Caddy is configured using a plain text file called Caddyfile. The Caddyfile starts with (an optional global options block and) an address of the site to be served, and is followed by a number of directives.

A simple Caddyfile hosting the site at localhost:2020:

{
  http_port 2020
}

localhost:2020
file_server

Usage

$ caddy help
$ caddy help run

Caddy can be run by any user from the page's directory, and the Caddyfile should be in the same directory:

$ caddy run

Alternatively you may specify a custom Caddyfile:

$ caddy run --config ../path/to/Caddyfile

Troubleshooting

Certificate error

If you are facing any issues related to SSL certificates (especially on non-public domains), it is probably because the running caddy instance does not have permission to add the certificate to the system's trust store. This seems to be the case when caddy.service is used to autostart caddy.

To fix this, run the following as root. You only have to run this once in a very long time (lifetime of the root certificate).

# XDG_DATA_HOME=/var/lib caddy trust

See also