Configuring the reverse proxy for Apache webserver using Ansible

Jyoti Pawar
3 min readApr 1, 2021

Here we will configure the Apache webserver and haproxy using ansible

We will manage the load of our site by haproxy(Reverse Proxy) and will automatically configure the configuration file of haproxy using ANSIBLE as automation tool.

The task here is:

12.1 Use Ansible playbook to Configure Reverse
Proxy i.e. Haproxy and update it’s configuration
file automatically on each time new Managed node
(Configured With Apache Webserver) join the inventory.

So let’s start…..

What is Ansible?

Ansible in short we use for configuration management and its an automation tool used widely nowadays.

It is primarily intended for IT professionals, who use it for application deployment, updates on workstations and servers, cloud provisioning, configuration management, intra-service orchestration, and nearly anything a systems administrator does on a weekly or daily basis. Ansible doesn’t depend on agent software and has no additional security infrastructure, so it’s easy to deploy.

What is Haproxy?

HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for very high traffic web sites and powers quite a number of the world’s most visited ones. Over the years it has become the de-facto standard opensource load balancer, is now shipped with most mainstream Linux distributions, and is often deployed by default in cloud platforms

What is Apache webserver?

Apache is a popular open-source, cross-platform web server that is, by the numbers, the most popular web server in existence. It’s actively maintained by the Apache Software Foundation.

Apache is the most commonly used Web server on Linux systems. Web servers are used to serve Web pages requested by client computers. Clients typically request and view Web pages using Web browser applications such as Firefox, Opera, Chromium, or Internet Explorer.

Users enter a Uniform Resource Locator (URL) to point to a Web server by means of its Fully Qualified Domain Name (FQDN) and a path to the required resource

LET’S START WITH OUR TASK…

The main reason here of Haproxy configuration is:

Whenever each time a new server at the backend is configured, then we need to include that server’s information in the configuration of the haproxy .

So is a cumbersome task. So here I have automated this task as well along with the configuration of apache webserver and haproxy.

So here I have created a playbook for the same

This above playbook will configure the apache webserver,haproxy and also update the configuration file of haproxy automatically as new server is added in the backend.

When we connect to our site , the haproxy balances the load equally to both the servers.

lets see how….

When I initially connected to the reverse proxy it got connected to webserver1 — you can see the IP of that server below. Second time when i refreshed the page it got connected to webserver2.(see the IP, its changed)

Initial connection
second time connecton after refreshing a page

So this helps to reduce the traffic of customers coming at single server.

So now first client can connect to webserver 1 and second client to webserver2 with the same content on both the sites. This is the same way in the real world these servers are working.

GitHub link:

https://github.com/jyotisp/Apache-webserver-and-haproxy-configuration

I hope you all would love this blog .

Thanks for reading ☺️☺️

--

--

Jyoti Pawar

Devops || AWS || ML || Deep learning || Python || Flask || Ansible RH294 || OpenShift DO180