瀏覽代碼

Fix ACME HTTP-01 passthrough in HAProxy config

Add an ACL that routes /.well-known/acme-challenge/ requests on :80
to Caddy instead of redirecting to HTTPS, so Let's Encrypt certificate
issuance works out of the box.

Also simplify Caddyfile to use Caddy's http_port/https_port directives.
pull/462/head
dolonet 3 週之前
父節點
當前提交
d0412b21f6
共有 4 個檔案被更改,包括 19 行新增24 行删除
  1. 5
    13
      contrib/sni-router/Caddyfile
  2. 3
    10
      contrib/sni-router/README.md
  3. 1
    0
      contrib/sni-router/docker-compose.yml
  4. 10
    1
      contrib/sni-router/haproxy.cfg

+ 5
- 13
contrib/sni-router/Caddyfile 查看文件

@@ -1,19 +1,11 @@
1 1
 {
2
-	# Caddy listens on 8443 behind HAProxy, which passes raw TLS through.
3
-	# Caddy terminates TLS itself and auto-obtains a Let's Encrypt certificate.
4
-	#
5
-	# If your domain's DNS already points to this server, ACME HTTP-01 challenge
6
-	# works through the HAProxy http frontend (:80 → redirect).  For DNS-01
7
-	# or other ACME methods, see https://caddyserver.com/docs/automatic-https
2
+	# Caddy sits behind HAProxy which passes raw TLS through on :8443.
3
+	# ACME HTTP-01 challenges arrive on :80 via HAProxy's acl passthrough.
4
+	http_port 80
5
+	https_port 8443
8 6
 }
9 7
 
10
-{$DOMAIN}:8443 {
11
-	tls {
12
-		# Use the ACME HTTP-01 challenge on port 80.
13
-		# HAProxy forwards :80 as HTTP, so Caddy can answer the challenge
14
-		# if you add an acl exception in haproxy.cfg (see README), or use
15
-		# DNS-01 instead.
16
-	}
8
+{$DOMAIN} {
17 9
 	root * /srv
18 10
 	file_server
19 11
 }

+ 3
- 10
contrib/sni-router/README.md 查看文件

@@ -45,16 +45,9 @@ docker compose exec mtg mtg access /config/config.toml
45 45
 
46 46
 ## ACME (Let's Encrypt) notes
47 47
 
48
-Caddy needs to answer the ACME HTTP-01 challenge on port 80.  The
49
-default `haproxy.cfg` redirects all `:80` traffic to HTTPS.  If Caddy
50
-cannot obtain a certificate, either:
51
-
52
-1. Temporarily stop HAProxy, let Caddy bind `:80` directly for the
53
-   initial certificate, then start the full stack; or
54
-2. Use DNS-01 validation in the Caddyfile (requires a DNS provider
55
-   plugin); or
56
-3. Add an HAProxy ACL that passes `/.well-known/acme-challenge/`
57
-   requests to the Caddy backend instead of redirecting.
48
+HAProxy passes `/.well-known/acme-challenge/` requests on `:80` to
49
+Caddy so that HTTP-01 validation works out of the box.  Make sure your
50
+domain's DNS A/AAAA record points to this server before starting.
58 51
 
59 52
 ## Architecture
60 53
 

+ 1
- 0
contrib/sni-router/docker-compose.yml 查看文件

@@ -44,6 +44,7 @@ services:
44 44
       - caddy_data:/data
45 45
       - ./www:/srv:ro
46 46
     expose:
47
+      - "80"
47 48
       - "8443"
48 49
     environment:
49 50
       DOMAIN: ${DOMAIN:-example.com}

+ 10
- 1
contrib/sni-router/haproxy.cfg 查看文件

@@ -20,11 +20,16 @@ defaults
20 20
     timeout client  60s
21 21
     timeout server  60s
22 22
 
23
-# --- HTTP :80 — redirect to HTTPS -------------------------------------------
23
+# --- HTTP :80 — ACME challenges + redirect -----------------------------------
24 24
 
25 25
 frontend http
26 26
     bind *:80
27 27
     mode http
28
+
29
+    # Let Caddy answer ACME HTTP-01 challenges for Let's Encrypt.
30
+    acl is_acme path_beg /.well-known/acme-challenge/
31
+    use_backend web_acme if is_acme
32
+
28 33
     http-request redirect scheme https code 301
29 34
 
30 35
 # --- TLS :443 — SNI-based routing -------------------------------------------
@@ -45,3 +50,7 @@ backend mtg
45 50
 
46 51
 backend web
47 52
     server web web:8443
53
+
54
+backend web_acme
55
+    mode http
56
+    server web web:80

Loading…
取消
儲存