-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCaddyfile
50 lines (42 loc) · 1.52 KB
/
Caddyfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{
on_demand_tls {
interval 2m
burst 10
ask "http://localhost:33214"
}
}
# A snippet with a couple of useful matchers
(subdomain_port) {
map {args.0} {subdomain_port} {
~^([^.]+\.)?(\d+)\..+\.[^\d]+$ "${2}"
default "0"
}
@reserved `{subdomain_port} in ["80", "22", "443"]`
@valid `{subdomain_port} != "0"`
@invalid `{subdomain_port} == "0"`
}
# Browsers start with HTTP request, so if the domain name is invalid, return an error message to avoid trying to get certificate
http:// {
import subdomain_port {host}
redir @valid https://{host}{uri}
respond "Unable to find proxy port number in the domain name {host}. (Powered by @ziolko/tunnel)"
}
https:// {
tls {
on_demand
}
import subdomain_port {host}
respond @reserved "Please pick another port because this one is reserved. (Powered by @ziolko/tunnel)"
respond @invalid "Unable to find proxy port number in the domain name {host} (Powered by @ziolko/tunnel)"
reverse_proxy @valid localhost:{subdomain_port}
handle_errors {
@badGateway `{err.status_code} == 502`
respond @badGateway "Unable to connect to service at port {subdomain_port}. Please check if the service is running there. (Powered by @ziolko/tunnel)"
}
}
# Utility endpoint to reduce number of requested certificates to domains with port in name
http://localhost:33214 {
import subdomain_port {query.domain}
respond @valid 200
respond 400
}