我有一个简单的代理,它监听同一端口上的HTTP和HTTPS连接。
然而,我看到奇怪的TLS握手错误,似乎是由Heroku路由器引起的:
heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=GET path="/favicon.ico" host=banana.camp request_id=f56144c8-e480-476a-90b8-429b490f1ff5 fwd="24.67.185.77" dyno=web.1 connect=0ms service=1ms status=503 bytes=7 protocol=https
http: TLS handshake error from 10.81.159.108:19578: tls: first record does not look like a TLS handshake
http: TLS handshake error from 172.17.117.25:36924: EOF有没有办法修复或忽略它们?任何线索都非常感谢。
谢谢!
func InitServer() error {
m := autocert.Manager{
Cache: autocert.DirCache(*StorageDir),
Prompt: autocert.AcceptTOS,
HostPolicy: func(ctx context.Context, host string) error {
return nil
},
}
errchan := make(chan error)
s := &http.Server{
Addr: ":" + os.Getenv("PORT"),
TLSConfig: &tls.Config{GetCertificate: m.GetCertificate},
Handler: ServeHTTP(),
}
go (func() {
errchan <- http.ListenAndServe(":"+os.Getenv("PORT"), m.HTTPHandler(nil))
})()
errchan <- s.ListenAndServeTLS("", "")
return <-errchan
}
func ServeHTTP() http.Handler {
return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
if upstreams, ok := Hosts[req.Host]; ok {
forwarder, _ := forward.New(forward.PassHostHeader(true))
loadbalancer, _ := roundrobin.New(forwarder)
for _, upstream := range upstreams {
if url, err := url.Parse(upstream); err == nil {
loadbalancer.UpsertServer(url)
} else {
log.Fatal("InitHostsList: ", err)
}
}
loadbalancer.ServeHTTP(res, req)
return
}
http.Error(res, "The request service couldn't be found here", http.StatusNotImplemented)
})
}发布于 2018-09-24 03:21:28
TLS终止由Heroku路由器处理,不能在应用程序级别¯_(ツ)_/‘完成
发布于 2018-09-23 07:13:43
你不能在同一个端口同时监听http和https,当你让http客户端尝试连接到应用程序时,就会出现这些日志错误。
发布于 2018-09-23 09:44:33
默认情况下,golang http服务器只支持侦听给定端口上的http或https流量(不能同时侦听两者)。要监听https流量,您需要使用http.ListenAndServeTLS。
如果您在仅为一个配置的点同时定向http和https流量,您将最终看到错误。
有一些第三方解决方案(如cmux)支持在同一端口上托管安全和不安全流量。分离端口不像分离端口那么简单,但是如果您想要做的事情,它们在自述文件中有一个示例配置。
https://stackoverflow.com/questions/52461409
复制相似问题