Ho installato TLS e funziona. So come riscrivere da http a https in nginx, ma non uso più nginx. Non so come farlo in Go correttamente.Come posso riscrivere/reindirizzare da http a https in 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!"))
}
Come farei questo in un buon modo?
grazie mille! – Alex
per l'indirizzo a cui reindirizzare, starai meglio usando "" https: // "+ r.Host + r.RequestURI', che eviterà che il tuo nome host o indirizzo IP sia codificato. –