go - 使用Iris将HTTP转发到https

标签 go iris-go

我正试图找出如何用“ris”和https://iris-go.com/v10/recipe#Secure57库构建我的golang应用程序来实现这一点。应用程序托管在gce上,带有一个工作的ssl负载平衡器。
这是我的应用程序:

s := secure.New(secure.Options{
        AllowedHosts:            []string{"mydomain.io"},
        SSLRedirect:             true,
        SSLTemporaryRedirect:    false,
        SSLHost:                 "",
        SSLProxyHeaders:         map[string]string{"X-Forwarded-Proto": "https"},
        STSSeconds:              315360000,
        STSIncludeSubdomains:    true,
        STSPreload:              true,
        ForceSTSHeader:          false,
        FrameDeny:               true,
        CustomFrameOptionsValue: "SAMEORIGIN",
        ContentTypeNosniff:      true,
        BrowserXSSFilter:        true,
        ContentSecurityPolicy:   "default-src *; style-src *; https://fonts.googleapis.com/css?family=Roboto+Mono:400,100,300italic,300,100italic,400italic,500,500italic,700,700italic&subset=latin,cyrillic",
        PublicKey:               ``,
        IsDevelopment:           false,
    })

    app := iris.New()
    app.Use(s.Serve)
    app.Use(recover.New())

当我在浏览器中键入mydomain.io时,它不会将其转发到https。少了什么?

最佳答案

这里不需要使用secure中间件,您只需要第二个web服务器将all:80重定向到:443,iris也有这样的例子,看看:https://github.com/kataras/iris/blob/master/_examples/http-listening/listen-tls/main.go#L22

// to start a new server listening at :80 and redirects
// to the secure address, then:
target, _ := url.Parse("https://127.0.1:443")
go host.NewProxy("127.0.0.1:80", target).ListenAndServe()

// start the server (HTTPS) on port 443, this is a blocking func,
// you can use iris.AutoTLS for letsencrypt if you want so.
app.Run(iris.TLS("127.0.0.1:443", "mycert.cert", "mykey.key"))

玩得高兴!

关于go - 使用Iris将HTTP转发到https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49968215/

相关文章:

json - 在 JSON 对象中发送数组时出错

vue.js - 刷新gin-gonic中的静态文件

go - Go中的线程安全值接收器

azure - Go客户端示例获取存储帐户 key

go - map 类型是引用类型。 var m map[string]int 不指向初始化的映射。这是什么意思?

去模板函数