【发布时间】:2016-05-31 02:38:52
【问题描述】:
我已经设置了 TLS 并且它可以工作。我知道如何在 nginx 中从 http 重写为 https,但我不再使用 nginx。我不知道如何在 Go 中正确执行此操作。
func main() {
certificate := "/srv/ssl/ssl-bundle.crt"
privateKey := "/srv/ssl/mykey.key"
http.HandleFunc("/", rootHander)
// log.Fatal(http.ListenAndServe(":80", nil))
log.Fatal(http.ListenAndServeTLS(":443", certificate, privateKey, nil))
}
func rootHander(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("To the moon!"))
}
我该如何以一种好的方式做到这一点?
【问题讨论】:
标签: go