3 homepage: https://github.com/caddyserver/caddy
5 Caddy is a fast, multi-platform web server with automatic HTTPS.
8 To update or switch versions, run `webi caddy@stable` (or `@v2.4`, `@beta`,
13 > Caddy makes it easy to use Let's Encrypt to handle HTTPS (TLS/SSL) and to
14 > reverse proxy APIs and WebSockets to other apps - such as those written node,
15 > Go, python, ruby, and PHP.
17 Here's the things we find most useful:
19 - Simple File & Directory Server
20 - Reverse Proxy with www (and HTTPS) redirects
21 - Running as a system service on
26 ### How to serve a directory
29 caddy file-server --browse --listen :4040
32 ### How to redirect and reverse proxy
34 Here's what a fairly basic `Caddyfile` looks like:
37 # redirect www to bare domain
39 redir https://example.com{uri} permanent
43 # log to stdout, which is captured by journalctl
49 # turn on standard streaming compression
52 # reverse proxy /api to :3000
53 reverse_proxy /api/* localhost:3000
55 # reverse proxy some "well known" APIs
56 reverse_proxy /.well-known/openid-configuration localhost:3000
57 reverse_proxy /.well-known/jwks.json localhost:3000
59 # serve static files from public folder, but not /api
62 try_files {path} {path}/ {path}/index.html
65 not path /.well-known/openid-configuration
66 not path /.well-known/jwks.json
69 rewrite @notApi {http.matchers.file.relative}
71 root * /srv/example.com/public/
76 And here's how you run caddy with it:
79 caddy run --config ./Caddyfile
82 ### How to start Caddy as a Linux service
84 Here are the 3 things you need to do to start Caddy as a system service:
88 If you don't have a non-root user, consider adding the `app` user with
89 [`ssh-adduser`](https://webinstall.dev/ssh-adduser).
91 Using a user named `app` to run your services is common industry convention.
93 **port-binding privileges**
95 You can use `setcap` to allow Caddy to use privileged ports.
98 sudo setcap cap_net_bind_service=+ep $(readlink -f $(command -v caddy))
103 You can use [`serviceman`](https://webinstall.dev/serviceman) to create and
104 start the appropriate systemd launcher for Linux.
106 Install Serviceman with Webi:
112 Use Serviceman to create a _systemd_ config file.
115 sudo env PATH="$PATH" \
116 serviceman add --system --username $(whoami) --name caddy -- \
117 caddy run --config ./Caddyfile
120 This will create `/etc/systemd/system/caddy.service`, which can be managed with
121 `systemctl`. For example:
124 sudo systemctl restart caddy
127 ### How to start Caddy as a MacOS Service
129 **Port-Binding Permission**
131 Caddy must run as the `root` user in order to bind to ports 80 and 443.
135 You can use [`serviceman`](https://webinstall.dev/serviceman) to create and
136 start the appropriate service launcher file for MacOS.
138 Install Serviceman with Webi:
144 Use Serviceman to create a _launchd_ plist file.
147 serviceman add --username $(whoami) --name caddy -- \
148 caddy run --config ./Caddyfile
151 This will create `~//Library/LaunchAgents/caddy.plist`, which can be managed
152 with `launchctl`. For example:
155 launchctl unload -w "$HOME/Library/LaunchAgents/caddy.plist"
156 launchctl load -w "$HOME/Library/LaunchAgents/caddy.plist"
159 ### How to start Caddy as a Windows Service
161 You may need to update the Windows Firewall to allow traffic through to Caddy.
162 You'll also need to create a Startup entry in the registry, which can be done
167 You can use PowerShell to update the firewall, which looks something like this:
170 powershell.exe -WindowStyle Hidden -Command $r = Get-NetFirewallRule -DisplayName 'Caddy Web Server' 2> $null; if ($r) {write-host 'found rule';} else {New-NetFirewallRule -DisplayName 'Go Web Server' -Direction Inbound C:\\Users\\YOUR_USER\\.local\\bin\\caddy.exe -Action Allow}
175 You can use [Serviceman](https://webinstall.dev/serviceman) to create and start
176 the appropriate service launcher for Windows 10.
178 Install Serviceman with Webi:
184 Use Serviceman to create a Startup entry in the Windows Registry:
187 serviceman.exe add --name caddy -- \
188 caddy run --config ./Caddyfile
191 You can manage the service directly with Serviceman. For example:
194 serviceman stop caddy
195 serviceman start caddy