Skip to content

Instantly share code, notes, and snippets.

@clarkezone
Last active September 11, 2020 03:05
Show Gist options
  • Save clarkezone/0000a9057bd973000057e31f1085ccfc to your computer and use it in GitHub Desktop.
Save clarkezone/0000a9057bd973000057e31f1085ccfc to your computer and use it in GitHub Desktop.
Hello World for a SSH using Let's Encrypt in GoLang using nGrok and acme autocert
package main
import (
"crypto/tls"
"log"
"net/http"
"fmt"
"golang.org/x/crypto/acme/autocert"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])
})
//let's encrypt
certManager := autocert.Manager{
Prompt: autocert.AcceptTOS,
HostPolicy: autocert.HostWhitelist("example.com"), //Your domain here
Cache: autocert.DirCache("certs"), //Folder for storing certificates
}
server := &http.Server{
Addr: ":8443",
TLSConfig: &tls.Config{
GetCertificate: certManager.GetCertificate,
},
}
go http.ListenAndServe(":8080", certManager.HTTPHandler(nil))
log.Fatal(server.ListenAndServeTLS("", ""))
}
authtoken: <ngrok_token>
tunnels:
myapp-http:
addr: 8080
proto: http
hostname: example.com
bind_tls: false
mypp-https:
addr: 8443
proto: tls
hostname: example.com
ngrok start -config=ngrokconfig.yaml --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment