差别
这里会显示出您选择的修订版和当前版本之间的差别。
| 后一修订版 | 前一修订版 | ||
| caddy [2026/06/26 02:50] – 创建 xiaobenmao | caddy [2026/06/27 08:41] (当前版本) – xiaobenmao | ||
|---|---|---|---|
| 行 37: | 行 37: | ||
| ===== Config ===== | ===== Config ===== | ||
| - | Write '' | + | Write '' |
| - | <code - [enable_line_numbers=" | + | For any change in '' |
| + | |||
| + | < | ||
| + | cd ~/ | ||
| + | docker compose exec caddy caddy validate | ||
| + | docker compose exec caddy caddy reload --config / | ||
| + | </ | ||
| + | |||
| + | ==== Host a static site ==== | ||
| + | |||
| + | <code text [enable_line_numbers=" | ||
| + | xiaobenmao.win { | ||
| + | encode zstd gzip | ||
| + | root * /srv/www | ||
| + | file_server | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Need to ensure the root path in docker container, here ''/ | ||
| + | |||
| + | ==== Map to a site (reverse_proxy) ==== | ||
| + | |||
| + | <code text [enable_line_numbers=" | ||
| auth.xiaobenmao.win { | auth.xiaobenmao.win { | ||
| reverse_proxy authentik-server-1: | reverse_proxy authentik-server-1: | ||
| 行 54: | 行 76: | ||
| </ | </ | ||
| - | For any change | + | ==== Redirect ==== |
| + | |||
| + | <code text [enable_line_numbers=" | ||
| + | www.xiaobenmao.win { | ||
| + | redir https:// | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | '' | ||
| + | |||
| + | ==== Authentication required page (with Authentik) ==== | ||
| + | |||
| + | <code text [enable_line_numbers=" | ||
| + | url.to.website { | ||
| + | encode zstd gzip | ||
| + | |||
| + | # Authentik outpost | ||
| + | handle / | ||
| + | reverse_proxy authentik-server-1: | ||
| + | } | ||
| + | |||
| + | # sample: no need auth for index page | ||
| + | handle index.html { | ||
| + | reverse_proxy xxx:80 | ||
| + | } | ||
| + | |||
| + | # rest pages need auth | ||
| + | handle { | ||
| + | forward_auth authentik-server-1: | ||
| + | uri / | ||
| + | copy_headers X-Authentik-Username X-Authentik-Groups X-Authentik-Email X-Authentik-Name | ||
| + | } | ||
| + | |||
| + | reverse_proxy xxx:80 | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | Take note the '' | ||
| + | |||
| + | Then create a new forward auth provider in Authentik. Go to Applications - Providers - New Provider, select Proxy Provider, and fill in details. Select authorization flow as default-provider-authorization-implicit-consent (Authorize Application), | ||
| + | |||
| + | {{pasted: | ||
| + | |||
| + | After that, create a new application with this provider. Bind users or access groups to this application. | ||
| + | |||
| + | Add the application into default outpost (authentik Embedded Outpost) via Applications - Outposts. | ||
| + | |||
| + | Testing should have 302 response for auth required page, while the remaining pages are normal. | ||
| <code bash> | <code bash> | ||
| - | cd ~/ | + | curl -I https://url.to.website/index.html |
| - | docker compose exec caddy caddy validate | + | curl -I https://url.to.website/test.html |
| - | docker compose exec caddy caddy reload --config | + | |
| </ | </ | ||