diff --git a/docs/index.md b/docs/index.md index f72a39dbb..de2ea0ea2 100644 --- a/docs/index.md +++ b/docs/index.md @@ -202,7 +202,15 @@ To enable it: ```toml [web] address = ":8080" + +# SSL certificate and key used +# +# Optional +# +# CertFile = "traefik.crt" +# KeyFile = "traefik.key" ``` + * ```/```: provides a simple HTML frontend of Træfik ![HTML frontend](img/web.frontend.png) diff --git a/traefik.sample.toml b/traefik.sample.toml index 652489b8e..ef3566dc7 100644 --- a/traefik.sample.toml +++ b/traefik.sample.toml @@ -66,6 +66,13 @@ # # address = ":8080" +# SSL certificate and key used +# +# Optional +# +# CertFile = "traefik.crt" +# KeyFile = "traefik.key" + ################################################################ # File configuration backend diff --git a/web.go b/web.go index f15d32fc3..e6d4e7415 100644 --- a/web.go +++ b/web.go @@ -11,6 +11,7 @@ import ( type WebProvider struct { Address string + CertFile, KeyFile string } type Page struct { @@ -43,7 +44,13 @@ func (provider *WebProvider) Provide(configurationChan chan<- *Configuration) { systemRouter.Methods("GET").Path("/api/frontends/{frontend}").Handler(http.HandlerFunc(GetFrontendHandler)) systemRouter.Methods("GET").PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, Prefix: "static"}))) - go http.ListenAndServe(provider.Address, systemRouter) + go func() { + if len(provider.CertFile) > 0 && len(provider.KeyFile) > 0 { + http.ListenAndServeTLS(provider.Address,provider.CertFile, provider.KeyFile, systemRouter) + } else { + http.ListenAndServe(provider.Address, systemRouter) + } + }() } func GetConfigHandler(rw http.ResponseWriter, r *http.Request) {