caddy

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录 前一修订版
caddy [2026/06/26 06:05] xiaobenmaocaddy [2026/06/27 08:41] (当前版本) xiaobenmao
行 49: 行 49:
 ==== Host a static site ==== ==== Host a static site ====
  
-<code [enable_line_numbers="true"]>+<code text [enable_line_numbers="true"]>
 xiaobenmao.win { xiaobenmao.win {
     encode zstd gzip     encode zstd gzip
行 61: 行 61:
 ==== Map to a site (reverse_proxy) ==== ==== Map to a site (reverse_proxy) ====
  
-<code [enable_line_numbers="true"]>+<code text [enable_line_numbers="true"]>
 auth.xiaobenmao.win { auth.xiaobenmao.win {
     reverse_proxy authentik-server-1:9000     reverse_proxy authentik-server-1:9000
行 78: 行 78:
 ==== Redirect ==== ==== Redirect ====
  
-<code [enable_line_numbers="true"]>+<code text [enable_line_numbers="true"]>
 www.xiaobenmao.win { www.xiaobenmao.win {
     redir https://xiaobenmao.win{uri}     redir https://xiaobenmao.win{uri}
行 84: 行 84:
 </code> </code>
  
 +''{uri}'' will copy all path and parameters as-is to the redirected one. 
 +
 +==== Authentication required page (with Authentik) ====
 +
 +<code text [enable_line_numbers="true"]>
 +url.to.website {
 +    encode zstd gzip
 +
 +    # Authentik outpost
 +    handle /outpost.goauthentik.io/* {
 +        reverse_proxy authentik-server-1:9000
 +    }
 +
 +    # sample: no need auth for index page
 +    handle index.html {
 +        reverse_proxy xxx:80
 +    }
 +
 +    # rest pages need auth
 +    handle {
 +        forward_auth authentik-server-1:9000 {
 +            uri /outpost.goauthentik.io/auth/caddy
 +            copy_headers X-Authentik-Username X-Authentik-Groups X-Authentik-Email X-Authentik-Name
 +        }
 +
 +        reverse_proxy xxx:80
 +    }
 +}
 +
 +</code>
 +
 +Take note the ''caddy'' in ''uri /outpost.goauthentik.io/auth/caddy'' specify the host program, alternatives like ''/outpost.goauthentik.io/auth/nginx'' for Nginx and ''/outpost.goauthentik.io/auth/traefik'' for Traefik. Do not change it. 
 +
 +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), and type forward auth (single application). 
 +
 +{{pasted:20260627-080759.png?500}}{{pasted:20260627-080818.png?500}}
 +
 +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>
 +curl -I https://url.to.website/index.html
 +curl -I https://url.to.website/test.html
 +</code>
  • caddy.1782453906.txt.gz
  • 最后更改: 2026/06/26 06:05
  • xiaobenmao