Skip to main content

Autocert Example

Github StackBlitz

This example demonstrates how to set up a secure Go Fiber application using Let's Encrypt for automatic TLS certificate management with autocert.

Description

This project provides a starting point for building a secure web application with automatic TLS certificate management using Let's Encrypt. It leverages Fiber for the web framework and autocert for certificate management.

Requirements

Setup

  1. Clone the repository:

    git clone https://github.com/gofiber/recipes.git
    cd recipes/autocert
  2. Install the dependencies:

    go mod download
  3. Update the HostPolicy in main.go with your domain:

    m := &autocert.Manager{
    Prompt: autocert.AcceptTOS,
    HostPolicy: autocert.HostWhitelist("yourdomain.com"), // Replace with your domain
    Cache: autocert.DirCache("./certs"),
    }
  4. Run the application:

    go run main.go

The application should now be running on https://localhost.

Example Usage

  1. Open your browser and navigate to https://yourdomain.com (replace with your actual domain).

  2. You should see the message: This is a secure server 👮.

Conclusion

This example provides a basic setup for a Go Fiber application with automatic TLS certificate management using Let's Encrypt. It can be extended and customized further to fit the needs of more complex applications.

References