Golang 安裝SSL證書
一、下載Nginx格式的SSL證書。
yourdomain.com.crt
yourdomain.com.key
二、Golang使用SSL證書 Demo
package main
import (
"crypto/tls"
"log"
"net/http"
)
func main() {
server := http.NewServeMux()
server.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("Hello World!!
"))
})
cfg := &tls.Config{
MinVersion: tls.VersionTLS12,
CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
PreferServerCipherSuites: true,
CipherSuites: []uint16{
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
},
}
srv := &http.Server{
Addr: "127.0.0.1:443",
Handler: server,
TLSConfig: cfg,
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler), 0),
}
srv.ListenAndServeTLS("yourdomain.com.crt", "yourdomain.com.key")
}
※MySQL 安裝SSL證書
※Zijidelu lum 控制面板安裝SSL證書
※Vesta 安裝SSL
※cPanel 安裝SSL證書
※DirectAdmin 安裝SSL
TAG:PHP愛好者 |