caddyserver / certmagic

Automatic HTTPS for any Go program: fully-managed TLS certificate issuance and renewal
https://pkg.go.dev/github.com/caddyserver/certmagic?tab=doc
Apache License 2.0
4.89k stars 278 forks source link

README: Add hint about NextProtos for certmagic.TLS #251

Closed oliverpool closed 10 months ago

oliverpool commented 10 months ago

This hint is already present a couple of lines later, however I overlooked it in the large advanced usescase.

In my usecase I just want to customize the storage:

        // SETUP TLS
        certmagic.DefaultACME.Email = "redacted@example.org"
        certmagic.DefaultACME.Agreed = true
        certmagic.DefaultACME.DisableHTTPChallenge = true

        // bugfix will come here

        certConfig := certmagic.NewDefault()
        certConfig.Storage = &certmagic.FileStorage{
            Path: stateDir + ".certmagic",
        }
        tlsConfig := certConfig.TLSConfig()
        tlsConfig.NextProtos = append([]string{"h2", "http/1.1"}, tlsConfig.NextProtos...)

        ln, err = tls.Listen("tcp", addr, tlsConfig)
        if err != nil {
            return err
        }

        if err := certConfig.ManageAsync(ctx, domains); err != nil { // async to prevent systemd restart
            return fmt.Errorf("could not manage TLS certificates: %v", err)
        }