Forked from https://github.com/krishamoud/caddy-consul
go get github.com/chenjpu/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/chenjpu/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 := .}} http://{{$domain}}.xxx.com {
root /var/www/dev.xxx.com
gzip
proxy /services {
header_upstream Host {host}
header_upstream X-Real-IP {remote}
header_upstream X-Forwarded-For {remote}
header_upstream X-Forwarded-Proto {scheme}
max_conns 200
policy ip_hash
{{range $key, $service := $services}}upstream {{.Address}}:{{.ServicePort}}
{{end}}
}
rewrite / {
if {uri} not_starts_with /services
to {uri} /
}
}
{{end}}
The above will output something like this:
http://test-dev.xxx.com {
root /var/www/dev.xxx.com
gzip
proxy /services {
header_upstream Host {host}
header_upstream X-Real-IP {remote}
header_upstream X-Forwarded-For {remote}
header_upstream X-Forwarded-Proto {scheme}
max_conns 200
policy ip_hash
upstream 10.110.200.26:23530
}
rewrite / {
if {uri} not_starts_with /services
to {uri} /
}
}
- Tests
- Refactoring