How to enable let's encrypt tls certification on my own golang project?

I have a golang web server. I use fiber freamwork in this project. I am trying to get certification from let's encrypt. I deployed my project with docker, and published it, but when i trying to connect my website, browser says "This site cannot provide a secure connection". Here are my golang codes:

certManager := autocert.Manager{
        Prompt:     autocert.AcceptTOS,
        HostPolicy: autocert.HostWhitelist("oguzhanguler.dev", "www.oguzhanguler.dev"),
        Cache:      autocert.DirCache("certs"),
    }

    TLSConfig := &tls.Config{
        GetCertificate: certManager.GetCertificate,
    }
listener, _ := net.Listen("tcp", ":443")
listener = tls.NewListener(listener, TLSConfig)

app.Listener(listener)

After published the project, i get into docker container. I can see the "cert" file is created. Do you have any idea why i am encountered with this problem? Also here is the my docker container's inside :


inside of cers folder is : https://i.ibb.co/prDrkbW/certs.png
my app looks like have no problem at all and running : https://i.ibb.co/ZJH8y0v/uygulama.png

My domain is: oguzhanguler.dev

The operating system my web server runs on is (include version): alpine linux

My hosting provider: digitalocean

I can login to a root shell on my machine (yes or no, or I don't know): yes

The version of my client is (e.g. output of certbot --version or certbot-auto --version if you're using Certbot):

This is just the Let's Encrypt account key. It doesn't look like the certificate is successfully created by autocert.

I think your program is probably not working because of a combination of two reasons:

  1. You have port 80 closed on your firewall, so the HTTP challenge can't succeed
  2. You are not following the autocert example properly and are not enabling the required ALPN protocol for the TLS-ALPN challenge to succeed. I think if you follow the example by using certManager.TLSConfig() rather than building your own &tls.Config{}, things should work.

Please don't forget to make a volume mount for certs, otherwise you will hit rate limits and be unable to issue certificates.

6 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.