Skip to main content

Introduction

In this guide, we will walk through the steps to deploy https://mintcdn.com/thedailyprothomalo/VtlDC2UXePiaGJvq/icons/Traefik%20Proxy.svg?fit=max&auto=format&n=VtlDC2UXePiaGJvq&q=85&s=a78df8c6adb2cbea5db1be2782f1c608Traefik, a popular open-source reverse proxy and load balancer, and configure it to work with Cloudflare for enhanced security and performance.

Prerequisites

Before we begin, ensure you have the following prerequisites in place:
  • A server or virtual machine with Docker installed.
  • A Cloudflare account with a domain configured.
  • Basic knowledge of Docker and Traefik.

Logical Diagram

Step 1: Deploy Traefik with Docker

a. Create a docker-compose.yml file to define the Traefik service:

Notes:

  • Replace the placeholder bcrypt hash above with a real hash. You can generate one at https://bcrypt-generator.com/ or using the htpasswd tool.
  • Define external network for Traefik to communicate with other services
  • Define the external network for Traefik to communicate with other services
b. Create the necessary directories and files and change the directory permission for Traefik configuration:

Create the directory for Traefik data if it doesn’t exist

Create the acme.json file to store TLS certificates

Set strict permissions so only the owner can read/write (required by Traefik)

c. Create the traefik.yml configuration file inside the traefik-data directory:
d. Start the Traefik container using Docker Compose:

Step 2: Configure Cloudflare DNS

a. Log in to your Cloudflare account and navigate to the DNS settings for your domain. b. Add a CNAME record for your Traefik dashboard:
  • Type: CNAME
  • Name: traefik
  • Target: your-server-ip-or-domain
  • TTL: Auto c. Ensure that the proxy status is enabled (orange cloud icon) for the CNAME record.

Step 3: Access the Traefik Dashboard

  1. Open your web browser and navigate to https://traefik.your-domain.com.
  2. You should see the Traefik dashboard login prompt. Enter the username and password you configured in the docker-compose.yml file.
  3. Once logged in, you can monitor and manage your Traefik instance.

Conclusion

You have successfully deployed Traefik and configured it to work with Cloudflare. You can now take advantage of Traefik’s powerful features along with Cloudflare’s security and performance enhancements for your