Revel doesn't forward to port 443 when SSL ena

2019-04-11 00:12发布

I'm using Revel for a small app and added SSL. When I update the config to point to http.port = 443, requests to port 80 are rejected instead of being forwarded. Is there a way to fix this on the Revel Framework? Thank you.

# 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

标签: ssl go revel
1条回答
兄弟一词,经得起流年.
2楼-- · 2019-04-11 00:30

You could add a simple redirect handler yourself.

Try putting this in your app/init.go file:

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()

Note that in Revel's dev mode, you'll first have to access your app on port 443 to have Revel start up properly before your port 80 redirect code will be run.

查看更多
登录 后发表回答