Forked from https://github.com/brimstone/caddy-consul
go get github.com/krishamoud/caddy-consul
go get github.com/mholt/caddy/caddy
// github.com/mholt/caddy/caddy/caddymain/run.go
package caddymain
import (
"errors"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"runtime"
"strconv"
"strings"
"gopkg.in/natefinch/lumberjack.v2"
"github.com/xenolf/lego/acme"
"github.com/mholt/caddy"
// plug in the HTTP server type
_ "github.com/mholt/caddy/caddyhttp"
"github.com/mholt/caddy/caddytls"
// This is where other plugins get plugged in (imported)
_ "github.com/krishamoud/caddy-consul" // ADD THIS LINE
)
cd github.com/mholt/caddy/caddy
go get github.com/caddyserver/builds
go run build.go
This tells consul where to connect
export CONSUL=http://10.0.0.1:8500
This tells caddy where to look for the Caddyfile.tmpl template
export CADDYFILE_PATH=/path/to/Caddyfile.tmpl
Either add your newly built binary to your $PATH
or just run ./caddy
from where you built the application.
{{range $domain, $services := .}}{{$domain}}.example.com {
tls /etc/ssl/cert.crt /etc/ssl/star_example_com.key
gzip
proxy / {
policy ip_hash
{{range $key, $service := $services}}upstream {{.Address}}:{{.ServicePort}}
{{end}}
}
}
{{end}}
The above will output something like this:
dashboard.example.com {
tls /etc/ssl/cert.crt /etc/ssl/star_example_com.key
gzip
proxy / {
policy ip_hash
upstream 172.31.17.252:32835
}
}
league.example.com {
tls /etc/ssl/cert.crt /etc/ssl/star_example_com.key
gzip
proxy / {
policy ip_hash
upstream 172.31.17.252:32834
upstream 172.31.58.45:32837
}
}
todos.example.com {
tls /etc/ssl/cert.crt /etc/ssl/star_example_com.key
gzip
proxy / {
policy ip_hash
upstream 172.31.17.252:32836
}
}
- Tests
- Refactoring