autotls
autotls copied to clipboard
Why I can not get the response "pong" while I run the example1?
main.go:
package main
import (
"log"
"net/http"
"github.com/gin-gonic/autotls"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
// Ping handler
r.GET("/ping", func(c *gin.Context) {
c.String(http.StatusOK, "pong")
})
log.Fatal(autotls.Run(r, "example1.com", "example2.com"))
}
After running the main.go,I typed https://localhost:443/ping in browser, I just get "ERR_SSL_PROTOCOL_ERROR" wrong message.
And the console shows the error messages as below:
2023/01/22 17:58:05 http: TLS handshake error from [::1]:51238: acme/autocert: server name component count invalid
2023/01/22 17:58:05 http: TLS handshake error from [::1]:51239: acme/autocert: server name component count invalid
2023/01/22 17:58:05 http: TLS handshake error from [::1]:51240: acme/autocert: server name component count invalid
2023/01/22 17:58:06 http: TLS handshake error from [::1]:51241: acme/autocert: server name component count invalid
I don't know what happens. Who can tell me why?
You should use http://yourdomainname.com/ping. this package is used for redirect http request to https and meanwhile force you to use the domain configured to access. For use locally, you can edit your hosts
, resolving domain name you like to localhost. As for server, you should buy several domain name that resolved to your IP and configure it in autotls.