dongroufan6846 2015-06-08 09:21
浏览 331

在Beego中从HTTP切换到HTTPS

I try to switch from HTTP to HTTPS:

func handler(w http.ResponseWriter, req *http.Request) {
    w.Header().Set("Content-Type", "text/plain")
    w.Write([]byte("This is an example server.
"))
}

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)
    }
}

And I am getting the following error:

crypto/tls: failed to parse key PEM data

My application is running in HTTP mode now and I want it to run in HTTPS mode.

Can anyone suggest how to make it work in HTTPS?

  • 写回答

1条回答 默认 最新

  • dongshixingga7900 2015-06-09 05:33
    关注

    The error indicates that the key.pem file cannot be parsed (could be invalid or lacking permission to read its content). Make sure the file is valid and sufficient permissions are set.

    For testing purposes, use the generate_cert.go in the crypto/tls package to generate valid cert.pem and key.pem files.

    To generate, run the following command (windows):

    go run %GOROOT%/src/crypto/tls/generate_cert.go -host="127.0.0.1"
    

    Linux:

    go run $GOROOT/src/crypto/tls/generate_cert.go -host="127.0.0.1"
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决