使用Go - handshake错误设置Let加密

时间:2017-04-01 20:16:17

标签: ssl go ssl-certificate lets-encrypt

我试图在Go编写的负载均衡器上设置let加密,我尝试了自动和手动设置,但我总是遇到错误。

域名正确指向我们的服务器(数字海洋),我甚至可以从浏览器打开网站而不会出现错误,也可以在此域上检查ssl检查报告。事实是,当我从CLI运行服务器上的Go可执行文件时,我会反复出错。

  1. 自动(acme / autocert)设置:
  2. 服务器代码是,当我在服务器启动后第一次从浏览器中查看域时,会创建证书和密钥:

        go func() {
            log.Printf("Staring HTTP service on %s ...", ":80")
    
            http.HandleFunc("/*", http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
                http.Redirect(w, r, "https://" + app.Cfg.S_HOST + ":443" + r.RequestURI, http.StatusMovedPermanently)
            }))
    
            if err := http.ListenAndServe(":80", nil); err != nil {
                errs <- err
            }
    
        }()
    
    
    
        log.Printf("Staring HTTPS service on %s ...", ":443")
    
        http.HandleFunc("/hello", http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
            w.Header().Set("Content-Type", "text/plain")
            w.Write([]byte("This is an example server.\n"))
        }))
    
    
        certManager := autocert.Manager{
            Prompt:     autocert.AcceptTOS,
            HostPolicy: autocert.HostWhitelist(app.Cfg.S_HOST), //your domain here
            Cache:      autocert.DirCache("certs"), //folder for storing certificates
        }
    
        server := &http.Server{
            Addr: ":443",
            TLSConfig: &tls.Config{
                ServerName: app.Cfg.S_HOST,
                GetCertificate: certManager.GetCertificate,
            },
        }
    
        if err := server.ListenAndServeTLS("", ""); err != nil {
            print(err.Error())
        } //key and cert are comming from Let's Encrypt
    

    我收到了这些错误:

    1. http:来自(ip)的TLS握手错误:59451:读取tcp(myserver IP):443-&gt;(ip):59451:读取:通过对等方重置连接

    2. hello.ServerName为空:2017/04/01 17:14:38 http:来自(ip)的TLS握手错误:58193:acme / autocert:缺少服务器名称

    3. http:来自(ip)的TLS握手错误:45822:acme / autocert:主机未配置

    4. http:来自(ip)的TLS握手错误:58440:EOF

    5. 然后我尝试手动创建证书(成功)并简单地使用该代码,我一次又一次地得到错误:

      服务器代码是:

          go func() {
              log.Printf("Staring HTTP service on %s ...", ":80")
      
              http.HandleFunc("/*", http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
                  http.Redirect(w, r, "https://" + app.Cfg.S_HOST + ":443" + r.RequestURI, http.StatusMovedPermanently)
              }))
      
              if err := http.ListenAndServe(":80", nil); err != nil {
                  errs <- err
              }
      
          }()
      
      
      
          log.Printf("Staring HTTPS service on %s ...", ":443")
      
          http.HandleFunc("/hello", http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
              w.Header().Set("Content-Type", "text/plain")
              w.Write([]byte("This is an example server.\n"))
          }))
      
      
          // ssl["cert"] and ssl["key"] are the cert and key path (letsencrypt/live...)
          if err := http.ListenAndServeTLS(sslAddr, ssl["cert"], ssl["key"], nil); err != nil {
              errs <- err
          }
      

      错误:

      1. http2:server:错误从客户端(ip)读取前言:10319:伪造 问候&#34; POST / HTTP / 1.1 \ r \ n主持人:4&#34;

      2. http:来自(ip)的TLS握手错误:10322:EOF

      3. http:来自(ip)的TLS握手错误:13504:读取tcp(我的服务器ip):443-&gt;(ip):13504:读取:通过对等方重置连接

      4. http2:server:从客户端(ip)读取序言时出错:9672:超时等待客户端序言

      5. 是的,有人能帮帮我吗?感谢

1 个答案:

答案 0 :(得分:1)

正如JimB和其他人在评论中所说,这可能是不良请求的结果。使用https://www.ssllabs.com/ssltest/测试网站的https配置时,系统会记录无效请求。良好的测试分数可以让您确信日志消息是良性的,可以安全地忽略。

acme/autocert套餐也在快速发展(2018年1月),请检查您的版本是否是最新的。

相关问题