IRIS服务监听启用安全传输协议

目录结构

主目录listenTls

  1. —— main.go
  2. —— mycert.cert
  3. —— mykey.key

代码示例

main.go

  1. package main
  2. import (
  3. "net/url"
  4. "github.com/kataras/iris"
  5. "github.com/kataras/iris/core/host"
  6. )
  7. func main() {
  8. app := iris.New()
  9. app.Get("/", func(ctx iris.Context) {
  10. ctx.Writef("Hello from the SECURE server")
  11. })
  12. app.Get("/mypath", func(ctx iris.Context) {
  13. ctx.Writef("Hello from the SECURE server on path /mypath")
  14. })
  15. //启动一个新的服务器,监听:80并重定向,到安全地址,然后:
  16. target, _ := url.Parse("https://127.0.1:443")
  17. go host.NewProxy("127.0.0.1:80", target).ListenAndServe()
  18. //在端口443上启动服务器(HTTPS)这是一个阻塞功能
  19. app.Run(iris.TLS("127.0.0.1:443", "mycert.cert", "mykey.key"))
  20. }

mycert.cert

  1. -----BEGIN CERTIFICATE-----
  2. MIIDAzCCAeugAwIBAgIJAPDsxtKV4v3uMA0GCSqGSIb3DQEBBQUAMBgxFjAUBgNV
  3. BAMMDTEyNy4wLjAuMTo0NDMwHhcNMTYwNjI5MTMxMjU4WhcNMjYwNjI3MTMxMjU4
  4. WjAYMRYwFAYDVQQDDA0xMjcuMC4wLjE6NDQzMIIBIjANBgkqhkiG9w0BAQEFAAOC
  5. AQ8AMIIBCgKCAQEA0KtAOHKrcbLwWJXgRX7XSFyu4HHHpSty4bliv8ET4sLJpbZH
  6. XeVX05Foex7PnrurDP6e+0H5TgqqcpQM17/ZlFcyKrJcHSCgV0ZDB3Sb8RLQSLns
  7. 8a+MOSbn1WZ7TkC7d/cWlKmasQRHQ2V/cWlGooyKNEPoGaEz8MbY0wn2spyIJwsB
  8. dciERC6317VTXbiZdoD8QbAsT+tBvEHM2m2A7B7PQmHNehtyFNbSV5uZNodvv1uv
  9. ZTnDa6IqpjFLb1b2HNFgwmaVPmmkLuy1l9PN+o6/DUnXKKBrfPAx4JOlqTKEQpWs
  10. pnfacTE3sWkkmOSSFltAXfkXIJFK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0zc6bgbBFOGmJU8v
  25. pXhD88tsu9exptLkGVoYZjR0n0QT/2Kkyu93jVDW/80P7VCz8DKYyAJDa4CVwZxO
  26. MlobQSunSDKx/CCJhWkbytCyh1bngAtwSAYLXavYIlJbAzx6FvtAIw4=
  27. -----END RSA PRIVATE KEY-----