为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

Go
幕布斯7119047 2021-11-22 14:50:06
我将 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
查看完整描述

1 回答

?
有只小跳蛙

TA贡献1824条经验 获得超8个赞

您可以自己添加一个简单的重定向处理程序。


尝试将其放入您的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。


查看完整回答
反对 回复 2021-11-22
  • 1 回答
  • 0 关注
  • 151 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信