3
我尝试从HTTP切换到HTTPS:切换到HTTPS在Beego
func handler(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte("This is an example server.\n"))
}
func main() {
http.HandleFunc("/", handler)
log.Printf("About to listen on 8080. Go to https://127.0.0.1:8080/")
err := http.ListenAndServeTLS(":8080", "cert.pem", "key.pem", nil)
if err != nil {
log.Fatal(err)
}
}
而且我收到以下错误:
crypto/tls: failed to parse key PEM data
我的应用程序在HTTP模式下运行,现在和我希望它以HTTPS模式运行。
任何人都可以建议如何使它在HTTPS中工作?
确定'cert.pem'和'key.pem'文件是正确的(当前工作目录)文件夹?尝试传递绝对路径。 – icza
@icza,是的,它是在同一个文件夹中。即使尝试通过绝对路径它给出相同的错误。 –