diff --git a/docs/config.md b/docs/config.md
index 64a058a1..892c8b6a 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -13,8 +13,8 @@ The following environment variables can be used to configure the *Docker Flow Pr
|-------------------|----------------------------------------------------------|--------|-------|-------|
|BIND_PORTS |Ports to bind in addition to `80` and `443`. Multiple values can be separated with comma|No| |8085, 8086|
|CERTS |This parameter is **deprecated** as of February 2017. All the certificates from the `/cets/` directory are now loaded automatically| | | |
-|CONNECTION_MODE |HAProxy supports 5 connection modes.
*http-keep-alive*: all requests and responses are processed.
*http-tunnel*: only the first request and response are processed, everything else is forwarded with no analysis.
*httpclose*: tunnel with "Connection: close" added in both directions.
*http-server-close*: the server-facing connection is closed after the response.
*forceclose*: the connection is actively closed after end of response.
In general it is preferred to use *http-server-close* with application servers, and some static servers might benefit from *http-keep-alive*.|No|http-server-close|http-keep-alive|
-|CONSUL_ADDRESS |The address of a Consul instance used for storing proxy information and discovering running nodes. Multiple addresses can be separated with comma (e.g. 192.168.0.10:8500,192.168.0.11:8500).|Only in the *default* mode| |192.168.0.10:8500|
+|CONNECTION_MODE |HAProxy supports 5 connection modes.
`http-keep-alive`: all requests and responses are processed.
`http-tunnel`: only the first request and response are processed, everything else is forwarded with no analysis.
`httpclose`: tunnel with "Connection: close" added in both directions.
`http-server-close`: the server-facing connection is closed after the response.
`forceclose`: the connection is actively closed after end of response.
In general it is preferred to use `http-server-close` with application servers, and some static servers might benefit from `http-keep-alive`.|No|http-server-close|http-keep-alive|
+|CONSUL_ADDRESS |The address of a Consul instance used for storing proxy information and discovering running nodes. Multiple addresses can be separated with comma (e.g. 192.168.0.10:8500,192.168.0.11:8500).|Only in the `default` mode| |192.168.0.10:8500|
|DEFAULT_PORTS |The default ports used by the proxy. Multiple values can be separated with comma (`,`). If a port should be for SSL connections, append it with `:ssl.|No|80,443:ssl| |
|EXTRA_FRONTEND |Value will be added to the default `frontend` configuration.|No | | |
|EXTRA_GLOBAL |Value will be added to the default `global` configuration.|No | | |
diff --git a/proxy/ha_proxy_test.go b/proxy/ha_proxy_test.go
index c21d50de..60a16c74 100644
--- a/proxy/ha_proxy_test.go
+++ b/proxy/ha_proxy_test.go
@@ -488,6 +488,61 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_PutsServicesWithRootPat
s.Equal(expectedData, actualData)
}
+func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_PutsServicesWellKnownPathToTheBeginning() {
+ var actualData string
+ tmpl := s.TemplateContent
+ expectedData := fmt.Sprintf(
+ `%s
+ acl url_02-another-well-known-service1111 path_beg /.well-known/and/somrthing/else
+ use_backend 02-another-well-known-service-be1111 if url_02-another-well-known-service1111
+ acl url_02-well-known-service1111 path_beg /.well-known
+ use_backend 02-well-known-service-be1111 if url_02-well-known-service1111
+ acl url_01-first-service1111 path_beg /path
+ use_backend 01-first-service-be1111 if url_01-first-service1111
+ acl url_03-third-service1111 path_beg /path
+ use_backend 03-third-service-be1111 if url_03-third-service1111%s`,
+ tmpl,
+ s.ServicesContent,
+ )
+ writeFile = func(filename string, data []byte, perm os.FileMode) error {
+ actualData = string(data)
+ return nil
+ }
+ p := NewHaProxy(s.TemplatesPath, s.ConfigsPath)
+ // Will be listed third
+ data.Services["01-first-service"] = Service{
+ ServiceName: "01-first-service",
+ ServiceDest: []ServiceDest{
+ {Port: "1111", ServicePath: []string{"/path"}},
+ },
+ }
+ // Will be listed second bacause of the well-known path and service name
+ data.Services["02-well-known-service"] = Service{
+ ServiceName: "02-well-known-service",
+ ServiceDest: []ServiceDest{
+ {Port: "1111", ServicePath: []string{"/.well-known"}},
+ },
+ }
+ // Will be listed first because of the well-known path and service name
+ data.Services["02-another-well-known-service"] = Service{
+ ServiceName: "02-another-well-known-service",
+ ServiceDest: []ServiceDest{
+ {Port: "1111", ServicePath: []string{"/.well-known/and/somrthing/else"}},
+ },
+ }
+ // Will be listed last
+ data.Services["03-third-service"] = Service{
+ ServiceName: "03-third-service",
+ ServiceDest: []ServiceDest{
+ {Port: "1111", ServicePath: []string{"/path"}},
+ },
+ }
+
+ p.CreateConfigFromTemplates()
+
+ s.Equal(expectedData, actualData)
+}
+
func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsContentFrontEndTcp() {
var actualData string
tmpl := s.TemplateContent
diff --git a/proxy/types.go b/proxy/types.go
index 68753a2d..4a29a282 100644
--- a/proxy/types.go
+++ b/proxy/types.go
@@ -111,10 +111,18 @@ func (slice Services) Len() int {
func (slice Services) Less(i, j int) bool {
firstHasRoot := hasRoot(slice[i])
secondHasRoot := hasRoot(slice[j])
- if (firstHasRoot && secondHasRoot) || (!firstHasRoot && !secondHasRoot) {
- return slice[i].AclName < slice[j].AclName
- } else if firstHasRoot {
+ firstHasWelKnown := hasWellKnown(slice[i])
+ secondHasWelKnown := hasWellKnown(slice[j])
+ if firstHasRoot && !secondHasRoot {
+ return false
+ } else if !firstHasRoot && secondHasRoot {
+ return true
+ } else if firstHasWelKnown && !secondHasWelKnown {
+ return true
+ } else if !firstHasWelKnown && secondHasWelKnown {
return false
+ } else {
+ return slice[i].AclName < slice[j].AclName
}
return true
}
@@ -130,6 +138,17 @@ func hasRoot(service Service) bool {
return false
}
+func hasWellKnown(service Service) bool {
+ for _, sd := range service.ServiceDest {
+ for _, path := range sd.ServicePath {
+ if strings.HasPrefix(strings.ToLower(path), "/.well-known") {
+ return true
+ }
+ }
+ }
+ return false
+}
+
func (slice Services) Swap(i, j int) {
slice[i], slice[j] = slice[j], slice[i]
}