启用S​​SL后,Revel不会转发到端口443 [英] Revel doesn't forward to port 443 when SSL enabled

查看:200
本文介绍了启用S​​SL后,Revel不会转发到端口443的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 #侦听的端口。 
http.port = 443

#是否使用SSL。
http.ssl = true

#如果使用SSL,则指向X509证书文件的路径。
http.sslcert = /root/go/src/saml/AlphaCerts/cert.crt

#如果使用SSL,则指向X509证书密钥的路径。
http.sslkey = /root/go/src/saml/star_home_com.key


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



试着把它放在 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()

请注意,在Revel的开发模式下,您必须首先在端口443上访问您的应用程序,让Revel在启动端口80重定向代​​码之前正常启动。


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

解决方案

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.

这篇关于启用S​​SL后,Revel不会转发到端口443的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆