我正试图找出如何用“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/