Files
gorush/gorush/server_unix.go
Bo-Yi Wu 97eae1fab4 feat: support Automatically install TLS certificates from Let's Encrypt. (#205)
* feat: support Automatically install TLS certificates from Let's Encrypt.

* refactor: update tls server.

* fix: missing tls package.

* fix: drop 1.6.x support

* docs: update readme.

* fix: listen tcp :443: bind: permission denied
2017-04-05 12:03:43 +08:00

46 lines
1.0 KiB
Go

// +build !windows
package gorush
import (
"crypto/tls"
"net/http"
"github.com/facebookgo/grace/gracehttp"
)
// RunHTTPServer provide run http or https protocol.
func RunHTTPServer() (err error) {
if PushConf.Core.AutoTLS.Enabled {
err = gracehttp.Serve(autoTLSServer())
} else if PushConf.Core.SSL && PushConf.Core.CertPath != "" && PushConf.Core.KeyPath != "" {
config := &tls.Config{
MinVersion: tls.VersionTLS10,
}
if config.NextProtos == nil {
config.NextProtos = []string{"http/1.1"}
}
config.Certificates = make([]tls.Certificate, 1)
config.Certificates[0], err = tls.LoadX509KeyPair(PushConf.Core.CertPath, PushConf.Core.KeyPath)
if err != nil {
LogError.Error("Failed to load https cert file: ", err)
return err
}
err = gracehttp.Serve(&http.Server{
Addr: ":" + PushConf.Core.Port,
Handler: routerEngine(),
TLSConfig: config,
})
} else {
err = gracehttp.Serve(&http.Server{
Addr: ":" + PushConf.Core.Port,
Handler: routerEngine(),
})
}
return
}