启用 SSL 后,Revel 不会转发到端口 443
Revel doesn't forward to port 443 when SSL enabled
我将 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
您可以自己添加一个简单的重定向处理程序。
尝试将其放入您的 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 上访问您的应用才能让 Revel 正常启动,然后您的端口 80 重定向代码将为 运行。
我将 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
您可以自己添加一个简单的重定向处理程序。
尝试将其放入您的 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 上访问您的应用才能让 Revel 正常启动,然后您的端口 80 重定向代码将为 运行。