小程序开发服务器配置

// 在go18-examples/stdlib/http2-push目录下,执行:

$go run $GOROOT/src/crypto/tls/generate_cert.go --host 127.0.0.1

2017/01/27 10:58:01 written cert.pem

2017/01/27 10:58:01 written key.pem


func ListenAndServeTLS

func ListenAndServeTLS(addr, certFile, keyFilestring, handlerHandler)error

ListenAndServeTLS acts identically to ListenAndServe, except that it expects HTTPS connections. Additionally, files containing a certificate and matching private key for the server must be provided. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.

A trivial example server is:

import ("log""net/http")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 10443. Go tohttps://127.0.0.1:10443/")err := http.ListenAndServeTLS(":10443", "cert.pem", "key.pem", nil)log.Fatal(err)}

One can use generate_cert.go in crypto/tls to generate cert.pem and key.pem.

ListenAndServeTLS always returns a non-nil error.




进行公共CA证书转换:

openssl x509 -in 1_iot.syniot.cn_bundle.crt -out mycert.pem -outform PEM

openssl rsa -in 2_iot.syniot.cn.key -out mykey.pem -outform PEM

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home...
    光剑书架上的书阅读 3,943评论 2 8
  • https://nodejs.org/api/documentation.html 工具模块 Assert 测试 ...
    KeKeMars阅读 6,403评论 0 6
  • 在这个夏天我想做的最正确的事一个就是加入猫叔的行动营还有就是深圳十点阅读。在被拉到深圳十点的群里以后,大家开始活跃...
    我有一颗不安的心阅读 420评论 2 3
  • 不能强迫别人来爱自己,只能努力让自己成为值得爱的人,其余的事情则靠缘分。 一个人愿意等待,另一个人才愿意出现。想有...
    紫玲阅读 469评论 0 0
  • 《瞬变》里说的:圣人和混蛋之间的界限,真的不像我们想象的那么清晰;如果营造出正确的路径可以让混蛋变成圣人,那么正确...
    joink阅读 579评论 1 1