Autocert Example
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
-
Clone the repository:
git clone https://github.com/gofiber/recipes.git
cd recipes/autocert -
Install the dependencies:
go mod download
-
Update the
HostPolicy
inmain.go
with your domain:m := &autocert.Manager{
Prompt: autocert.AcceptTOS,
HostPolicy: autocert.HostWhitelist("yourdomain.com"), // Replace with your domain
Cache: autocert.DirCache("./certs"),
} -
Run the application:
go run main.go
The application should now be running on https://localhost
.
Example Usage
-
Open your browser and navigate to
https://yourdomain.com
(replace with your actual domain). -
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.