ยง2023-07-01

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

  1. Install
$ sudo pacman -S caddy
$ $ systemctl status caddy
โ—‹ caddy.service - Caddy web server
     Loaded: loaded (/usr/lib/systemd/system/caddy.service; disabled; preset: disabled)
     Active: inactive (dead)
       Docs: https://caddyserver.com/docs/
  1. Start running it
$ caddy
Caddy is an extensible server platform written in Go.

At its core, Caddy merely manages configuration. Modules are plugged
in statically at compile-time to provide useful functionality. Caddy's
standard distribution includes common modules to serve HTTP, TLS,
and PKI applications, including the automation of certificates.

To run Caddy, use:

	- 'caddy run' to run Caddy in the foreground (recommended).
	- 'caddy start' to start Caddy in the background; only do this
	  if you will be keeping the terminal window open until you run
	  'caddy stop' to close the server.

When Caddy is started, it opens a locally-bound administrative socket
to which configuration can be POSTed via a restful HTTP API (see
https://caddyserver.com/docs/api).
...

2.1. caddy run in the foregrouind

$ caddy run
2023/06/30 23:24:05.854	INFO	admin	admin endpoint started	{"address": "localhost:2019", "enforce_origin": false, "origins": ["//localhost:2019", "//[::1]:2019", "//127.0.0.1:2019"]}
2023/06/30 23:24:05.855	INFO	serving initial configuration
<-- Ctl-c
^C2023/06/30 23:26:12.404	INFO	shutting down	{"signal": "SIGINT"}
2023/06/30 23:26:12.404	WARN	exiting; byeee!! ๐Ÿ‘‹	{"signal": "SIGINT"}
2023/06/30 23:26:12.405	INFO	admin	stopped previous server	{"address": "localhost:2019"}
2023/06/30 23:26:12.405	INFO	shutdown complete	{"signal": "SIGINT", "exit_code": 0}
$ curl localhost:2019/config
<a href="/config/">Moved Permanently</a>.

This is not your website: the administration endpoint at localhost:2019 is used for controlling Caddy and is restricted to localhost by default.

2.2 caddy start in the background

 caddy start
2023/06/30 23:27:44.608	INFO	admin	admin endpoint started	{"address": "localhost:2019", "enforce_origin": false, "origins": ["//localhost:2019", "//[::1]:2019", "//127.0.0.1:2019"]}
2023/06/30 23:27:44.609	INFO	serving initial configuration
Successfully started Caddy (pid=1949) - Caddy is running in the background
[alexlai@x8664Arch ~]$ ps aux|grep 1949
alexlai     1949  0.8  0.3 1423100 44932 pts/0   Sl   07:27   0:00 caddy run --pingback 127.0.0.1:37647
alexlai     1961  0.0  0.0   7984  2432 pts/0    S+   07:27   0:00 grep --color=auto 1949
[alexlai@x8664Arch ~]$ kill -9 1949
[alexlai@x8664Arch ~]$ ps aux|grep 1949
alexlai     1965  0.0  0.0   7984  2432 pts/0    S+   07:28   0:00 grep --color=auto 1949