猿问

启用 SSL 时,Revel 不会转发到端口 443

我将 Revel 用于一个小应用程序并添加了 SSL。当我更新配置以指向 http.port = 443 时,对端口 80 的请求将被拒绝而不是被转发。有没有办法在 Revel 框架上解决这个问题?谢谢你。


# The port on which to listen.

http.port = 443


# Whether to use SSL or not.

http.ssl = true


# Path to an X509 certificate file, if using SSL.

http.sslcert = /root/go/src/saml/AlphaCerts/cert.crt


# Path to an X509 certificate key, if using SSL.

http.sslkey = /root/go/src/saml/star_home_com.key


幕布斯7119047
浏览 152回答 1
1回答

有只小跳蛙

您可以自己添加一个简单的重定向处理程序。尝试将其放入您的app/init.go文件中:httpRedirectServer := &http.Server{Addr: ":80", Handler: http.HandlerFunc(    func(w http.ResponseWriter, r *http.Request) {        http.Redirect(w, r, fmt.Sprintf("https://%s%s", r.Host, r.RequestURI),                       http.StatusMovedPermanently)    })}go httpRedirectServer.ListenAndServe()请注意,在 Revel 的开发模式下,您首先必须在端口 443 上访问您的应用程序,以便在运行端口 80 重定向代码之前正确启动 Revel。
随时随地看视频慕课网APP

相关分类

Go
我要回答