doujie7497 2017-10-28 16:35
浏览 527
已采纳

如何在Golang Web服务器上设置HTTPS?

I'm reading https://www.kaihag.com/https-and-go/ and bought an SSL certificate from Comodo which they emailed me a .zip file. All of the files I have so far look like this

csr.pem
private-key.pem
website.com.crt
website.com.ca-bundle
website.com.zip

The above website wants me to concatenate 3 .pem files which I don't have. Incidentally what is the reason the .pem files need to concatenated? Using the above files which haven't been modified, how can https be set up on a golang webserver?

  • 写回答

4条回答 默认 最新

  • doukuang1950 2017-10-28 16:40
    关注

    Use https://golang.org/pkg/net/http/#ListenAndServeTLS

    http.HandleFunc("/", handler)
    log.Printf("About to listen on 10443. Go to https://127.0.0.1:10443/")
    err := http.ListenAndServeTLS(":10443", "cert.pem", "key.pem", nil)
    log.Fatal(err)
    

    This isn't really a go question, but the intermediate certs are required because computers only store root certs. By concatenating them you put them all in one file so the browser gets all certs - this is a required step otherwise your server will fail on certain devices. Your cert provider will provide instructions for doing this. For go you need one cert file and one private key file.

    https://kb.wisc.edu/page.php?id=18923

    Here are some instructions for comodo for combining the certs (doesn't matter which server is used, the process is the same):

    https://support.comodo.com/index.php?/Knowledgebase/Article/View/1091/37/certificate-installation--nginx

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?