2015-11-05 34 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

相關問題