2015-11-05 37 views
3

我正在使用Revel进行小型应用并添加了SSL。当我更新配置指向http.port = 443时,端口80的请求被拒绝而不是被转发。有没有办法在Revel Framework上解决这个问题?谢谢。当SSL启用时,Revel不转发到端口443

# 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 

回答

5

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

尝试把这个在您的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() 

注意,在狂欢的开发模式,您首先需要访问端口443上您的应用程序有狂欢的80端口重定向代码之前正常启动将会运行。

+0

这工作没有任何改变你的代码。在将上面的代码放入func init()后,其他人需要注意导入net/http和fmt。谢谢! – vinniyo

相关问题