Skip to main content

Introduction

In this guide, we will walk through the steps to deploy https://mintcdn.com/thedailyprothomalo/BHFxhJnL0YxSMxN8/icons/haproxy.svg?fit=max&auto=format&n=BHFxhJnL0YxSMxN8&q=85&s=65943fc99ceb792b9b02a9d35d19e1c5HAProxy, a reliable and high-performance open-source load balancer and reverse proxy, within a Docker container. We will also configure automated SSL certificate management using Let’s Encrypt to ensure secure HTTPS connections.

HAProxy and Let’s Encrypt:

HAProxy is widely used in production environments for its robustness, scalability, and advanced load balancing capabilities. It efficiently distributes incoming traffic across multiple backend servers, enhancing application performance and reliability. Let’s Encrypt is a free, automated, and open certificate authority that provides SSL/TLS certificates to enable HTTPS on websites. By integrating Let’s Encrypt with HAProxy, we can automate the process of obtaining and renewing SSL certificates, ensuring that our applications remain secure without manual intervention.

Overview of the Deployment:

In this deployment, we will set up HAProxy as a reverse proxy in a Docker container. HAProxy will handle incoming HTTPS requests, route them to the appropriate backend services, and manage SSL certificates using Let’s Encrypt. The deployment will include the following key components:
  • HAProxy Docker Container: The core component that will run HAProxy and manage traffic routing.
  • Let’s Encrypt Integration: Automated SSL certificate issuance and renewal using the ACME protocol.
  • Backend Services: The applications or services that HAProxy will route traffic to.

Prerequisites

Before we begin, ensure you have the following prerequisites in place:
  • A server or virtual machine with Docker installed.
  • A domain name pointing to your server’s IP address.
  • Basic knowledge of Docker and HAProxy.

Logical Diagram

Directory Structure

Before we start, let’s outline the directory structure we will use for this deployment:

Step 1: Create HAProxy Configuration File

a. Create a file named haproxy.cfg in the /opt/haproxy/ directory with the following content:
b. Save and close the file.

Step 2: Create Docker Compose File

a. Create a file named docker-haproxy.yml in the /opt/haproxy/ directory with the following content:
b. Save and close the file.

Step 3: Create Certificates Directory

a. Create a directory named certs in the /opt/haproxy/ directory to store SSL certificates:

Step 4: Deploy HAProxy and Certbot Containers

a. Navigate to the /opt/haproxy/ directory:
b. Start the HAProxy and Certbot containers using Docker Compose:
c. Verify that the containers are running:
You should see both haproxy and certbot containers listed as running.

Step 5: Access HAProxy Stats Dashboard

  1. Open your web browser and navigate to http://your-server-ip:8080/stats.
  2. You should see the HAProxy statistics dashboard. Log in using the credentials specified in the haproxy.cfg file (username: admin, password: XXXXXXXX).

Conclusion

You have successfully deployed HAProxy in a Docker container with automated SSL certificate management using Let’s Encrypt. HAProxy is now set up to handle incoming HTTPS requests, route them to your backend services, and automatically renew SSL certificates as needed. You can monitor HAProxy’s performance and traffic through the stats dashboard.