mirror of
https://github.com/caddyserver/caddy.git
synced 2026-05-26 16:52:40 -04:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5968ebd0f4 | |||
| a5f4fae145 |
@@ -0,0 +1,46 @@
|
|||||||
|
:8884
|
||||||
|
|
||||||
|
reverse_proxy one|http://localhost two|http://localhost {
|
||||||
|
to three|srv+http://localhost four|srv+http://localhost
|
||||||
|
}
|
||||||
|
----------
|
||||||
|
{
|
||||||
|
"apps": {
|
||||||
|
"http": {
|
||||||
|
"servers": {
|
||||||
|
"srv0": {
|
||||||
|
"listen": [
|
||||||
|
":8884"
|
||||||
|
],
|
||||||
|
"routes": [
|
||||||
|
{
|
||||||
|
"handle": [
|
||||||
|
{
|
||||||
|
"handler": "reverse_proxy",
|
||||||
|
"upstreams": [
|
||||||
|
{
|
||||||
|
"dial": "localhost:80",
|
||||||
|
"id": "one"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dial": "localhost:80",
|
||||||
|
"id": "two"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "three",
|
||||||
|
"lookup_srv": "localhost"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "four",
|
||||||
|
"lookup_srv": "localhost"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,7 +34,8 @@ type adminUpstreams struct{}
|
|||||||
|
|
||||||
// upstreamResults holds the status of a particular upstream
|
// upstreamResults holds the status of a particular upstream
|
||||||
type upstreamStatus struct {
|
type upstreamStatus struct {
|
||||||
Address string `json:"address"`
|
ID string `json:"id"`
|
||||||
|
Address string `json:"address"` // Address is deprecated, should be removed in a future release.
|
||||||
Healthy bool `json:"healthy"`
|
Healthy bool `json:"healthy"`
|
||||||
NumRequests int `json:"num_requests"`
|
NumRequests int `json:"num_requests"`
|
||||||
Fails int `json:"fails"`
|
Fails int `json:"fails"`
|
||||||
@@ -78,7 +79,7 @@ func (adminUpstreams) handleUpstreams(w http.ResponseWriter, r *http.Request) er
|
|||||||
// Iterate over the upstream pool (needs to be fast)
|
// Iterate over the upstream pool (needs to be fast)
|
||||||
var rangeErr error
|
var rangeErr error
|
||||||
hosts.Range(func(key, val interface{}) bool {
|
hosts.Range(func(key, val interface{}) bool {
|
||||||
address, ok := key.(string)
|
id, ok := key.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
rangeErr = caddy.APIError{
|
rangeErr = caddy.APIError{
|
||||||
HTTPStatus: http.StatusInternalServerError,
|
HTTPStatus: http.StatusInternalServerError,
|
||||||
@@ -97,7 +98,8 @@ func (adminUpstreams) handleUpstreams(w http.ResponseWriter, r *http.Request) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
results = append(results, upstreamStatus{
|
results = append(results, upstreamStatus{
|
||||||
Address: address,
|
ID: id,
|
||||||
|
Address: id,
|
||||||
Healthy: !upstream.Unhealthy(),
|
Healthy: !upstream.Unhealthy(),
|
||||||
NumRequests: upstream.NumRequests(),
|
NumRequests: upstream.NumRequests(),
|
||||||
Fails: upstream.Fails(),
|
Fails: upstream.Fails(),
|
||||||
|
|||||||
@@ -219,6 +219,12 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
|||||||
// treated as a SRV-based upstream, and any port will be
|
// treated as a SRV-based upstream, and any port will be
|
||||||
// dropped.
|
// dropped.
|
||||||
appendUpstream := func(address string) error {
|
appendUpstream := func(address string) error {
|
||||||
|
var id string
|
||||||
|
if strings.Contains(address, "|") {
|
||||||
|
parts := strings.SplitN(address, "|", 2)
|
||||||
|
id = parts[0]
|
||||||
|
address = parts[1]
|
||||||
|
}
|
||||||
isSRV := strings.HasPrefix(address, "srv+")
|
isSRV := strings.HasPrefix(address, "srv+")
|
||||||
if isSRV {
|
if isSRV {
|
||||||
address = strings.TrimPrefix(address, "srv+")
|
address = strings.TrimPrefix(address, "srv+")
|
||||||
@@ -231,9 +237,9 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
|||||||
if host, _, err := net.SplitHostPort(dialAddr); err == nil {
|
if host, _, err := net.SplitHostPort(dialAddr); err == nil {
|
||||||
dialAddr = host
|
dialAddr = host
|
||||||
}
|
}
|
||||||
h.Upstreams = append(h.Upstreams, &Upstream{LookupSRV: dialAddr})
|
h.Upstreams = append(h.Upstreams, &Upstream{ID: id, LookupSRV: dialAddr})
|
||||||
} else {
|
} else {
|
||||||
h.Upstreams = append(h.Upstreams, &Upstream{Dial: dialAddr})
|
h.Upstreams = append(h.Upstreams, &Upstream{ID: id, Dial: dialAddr})
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,12 @@ type UpstreamPool []*Upstream
|
|||||||
type Upstream struct {
|
type Upstream struct {
|
||||||
Host `json:"-"`
|
Host `json:"-"`
|
||||||
|
|
||||||
|
// The unique ID for this upstream, to disambiguate multiple
|
||||||
|
// upstreams with the same Dial address. This is optional,
|
||||||
|
// and only necessary if the upstream states need to be
|
||||||
|
// separate, such as having different health checking policies.
|
||||||
|
ID string `json:"id,omitempty"`
|
||||||
|
|
||||||
// The [network address](/docs/conventions#network-addresses)
|
// The [network address](/docs/conventions#network-addresses)
|
||||||
// to dial to connect to the upstream. Must represent precisely
|
// to dial to connect to the upstream. Must represent precisely
|
||||||
// one socket (i.e. no port ranges). A valid network address
|
// one socket (i.e. no port ranges). A valid network address
|
||||||
@@ -98,6 +104,9 @@ type Upstream struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u Upstream) String() string {
|
func (u Upstream) String() string {
|
||||||
|
if u.ID != "" {
|
||||||
|
return u.ID
|
||||||
|
}
|
||||||
if u.LookupSRV != "" {
|
if u.LookupSRV != "" {
|
||||||
return u.LookupSRV
|
return u.LookupSRV
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user