After creating a webpage we upload it in a webserver which serves our page to the world. When many people start accessing our page this increases traffic in our page when this traffic increases it becomes difficult for a single server to manage this much traffic then we need more servers. But rather than creating more server and then creating one more webpage with different domain what we do is we create a proxy server which redirects requests to any of the background running servers on the same domain. This way it not only divides the traffic but also help in extreme cases when one of the server goes down.
This is also called load balancing or reverse proxy. To create such setup we need two or more systems.
First we need two running systems and their ips and to create this setup
Backend : 192.168.43.14
Load balancer : 192.168.43.122
Now we write a playbook that will configure httpd server on backend systems and haproxy in load balancer.
Also we need to tell haproxy server about who is his backend server where he needs to send requests. For this we update the haproxy configuration file and add backend ips and port.
We use jinja format for dynamically update the file from inventory.
now we run this playbook.
as you can see we have created the setup without any errors.