duanliaouu965826 2018-09-22 22:27
浏览 126

如何在Heroku上使用Go修复TLS握手错误?

I have a simple proxy that listens to HTTP and HTTPS connections on the same port.

However I'm seeing weird TLS handshake errors that seem to be caused by the Heroku router:

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

Is there any way to fix or ignore them? Any clues are greatly appreciated.

Thanks!

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)
    })
}
  • 写回答

3条回答 默认 最新

  • dongya1228 2018-09-22 23:13
    关注

    You can't listen to both http and https on the same port, and those log-errors are cases when you have http clients try to connect to the app.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题