I can think of two reasons why this is happening
- Your server application doesn't have access to port 443
- Your browser is trying to reach your server on port 80
Since the first issue can't be solved by the marked tags, this answer will cover the second case.
This problem happens because by default, when you type an address like www.domain.com, your browser tries to contact the url domain using the http protocol on port 80 and it's a known behavior that Golang ListenAndServeTLS returns data when not using https in the browser
Now, if you type in your browser the full URL with the proper scheme like https://www.domain.com
the browser will approach the server by the port 443 and start the TLS handshake with your server, thus rendering the correct data.
Now, you know this, but not your users. It would be really frustrating to your users to be notified by a SSL handshake error every time they try to access your web application using only your domain as URL.
In order to avoid this problem you could start a go routine with a server on port :80 (or 8080) that redirects all requests to port 443 with this simple piece of code:
// redir is a net.Http handler which redirects incoming requests to the
// proper scheme, in this case being https
func redir(w http.ResponseWriter, req *http.Request) {
hostParts := strings.Split(req.Host, ":")
http.Redirect(w, req, "https://"+hostParts[0]+req.RequestURI, http.StatusMovedPermanently)
}
func main() {
// this go subroutine creates a server on :8080 and uses the redir handler
go func() {
err := http.ListenAndServe(":8080", http.HandlerFunc(redir))
if err != nil {
panic("Error: " + err.Error())
}
}()
http.ListenAndServeTLS(":"+Config.String("port"), Config.Key("https").String("cert"), Config.Key("https").String("key"), router)
}
I hope it helped
Cheers,