diff --git a/cmd/server/handler.go b/cmd/server/handler.go index b473fa4fb58..496716a0d20 100644 --- a/cmd/server/handler.go +++ b/cmd/server/handler.go @@ -23,6 +23,7 @@ package server import ( "crypto/tls" "fmt" + "net" "net/http" "net/url" "strings" @@ -223,14 +224,23 @@ func serve(c *config.Config, cmd *cobra.Command, handler http.Handler, address s err := graceful.Graceful(func() error { var err error c.GetLogger().Infof("Setting up http server on %s", address) - if c.ForceHTTP { - c.GetLogger().Warnln("HTTPS disabled. Never do this in production.") - err = srv.ListenAndServe() - } else if c.AllowTLSTermination != "" { - c.GetLogger().Infoln("TLS termination enabled, disabling https.") - err = srv.ListenAndServe() + if strings.HasPrefix(address, "unix:") { + addr := strings.TrimPrefix(address, "unix:") + unixListener, e := net.Listen("unix", addr) + if e != nil { + return e + } + err = srv.Serve(unixListener) } else { - err = srv.ListenAndServeTLS("", "") + if c.ForceHTTP { + c.GetLogger().Warnln("HTTPS disabled. Never do this in production.") + err = srv.ListenAndServe() + } else if c.AllowTLSTermination != "" { + c.GetLogger().Infoln("TLS termination enabled, disabling https.") + err = srv.ListenAndServe() + } else { + err = srv.ListenAndServeTLS("", "") + } } return err diff --git a/config/config.go b/config/config.go index 00ac9e606a7..766fb20d291 100644 --- a/config/config.go +++ b/config/config.go @@ -425,12 +425,19 @@ func (c *Config) GetSystemSecret() []byte { return pkg.HashByteSecret(secret) } +func (c *Config) getAddress(address string, port int) string { + if strings.HasPrefix(address, "unix:") { + return address + } + return fmt.Sprintf("%s:%d", address, port) +} + func (c *Config) GetFrontendAddress() string { - return fmt.Sprintf("%s:%d", c.FrontendBindHost, c.FrontendBindPort) + return c.getAddress(c.FrontendBindHost, c.FrontendBindPort) } func (c *Config) GetBackendAddress() string { - return fmt.Sprintf("%s:%d", c.BackendBindHost, c.BackendBindPort) + return c.getAddress(c.BackendBindHost, c.BackendBindPort) } func (c *Config) Persist() error {