add log directive to simple example
[webi-installers/.git] / caddy / README.md
1 ---
2 title: Caddy
3 homepage: https://github.com/caddyserver/caddy
4 tagline: |
5   Caddy is a fast, multi-platform web server with automatic HTTPS.
6 ---
7
8 ## Updating `caddy`
9
10 ```bash
11 webi caddy@stable
12 ```
13
14 Use the `@beta` tag for pre-releases, or `@x.y.z` for a specific version.
15
16 ## Cheat Sheet
17
18 > Caddy makes it easy to use Let's Encrypt to handle HTTPS (TLS/SSL) and to
19 > reverse proxy APIs and WebSockets to other apps - such as those written node,
20 > Go, python, ruby, and PHP.
21
22 ### How to serve a directory
23
24 ```bash
25 caddy file-server --browse --listen :4040
26 ```
27
28 ### How to redirect and reverse proxy
29
30 Here's what a fairly basic `Caddyfile` looks like:
31
32 ```txt
33 # redirect www to bare domain
34 www.example.com {
35     redir https://example.com{uri} permanent
36 }
37
38 example.com {
39     # log to stdout, which is captured by journalctl
40     log {
41         output stdout
42         format console
43     }
44
45     # turn on standard streaming compression
46     encode gzip zstd
47
48     # reverse proxy /api to :3000
49     reverse_proxy /api/* localhost:3000
50
51     # serve static files from public folder, but not /api
52     @notApi {
53         file {
54             try_files {path} {path}/ /index.html
55         }
56         not path /api/*
57     }
58     route {
59       rewrite @notApi {http.matchers.file.relative}
60     }
61     root * /srv/example.com/public/
62     file_server
63 }
64 ```
65
66 And here's how you run caddy with it:
67
68 ```bash
69 caddy run --config ./Caddyfile
70 ```