Configuring Reverse
Proxy using Ansible playbook | Task 12.1 | Arth

Gaurav Sharma
3 min readSep 2, 2021

--

Overview

In this blog I am going to configure Reverse Proxy & backend servers & automate it using ansible.

Description

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.

Pre-Requisites

Before doing this task you should know concepts like Reverse Proxy & Load balancer & how to configure them.

Steps

  • Firstly we are going to configure backend server.
    There we install “httpd” & “php” packages.
  • Now write a ansible task for copying php web page to target node & start httpd service.
  • Now we are going to configure Proxy server.
    First we install HAproxy software & then we transfer “haproxy.cfg” file from local host to proxy server.

This “haproxy.cfg” file is not just a normal file it’s a dynamic file which automatically update it’s backend servers each time when a new Managed node join the inventory.

Output

  • Now let us run the playbook.
  • Let’s go inside each OS & check if we successful in our tasks.

Proxy Server :

Backend Server:

  • So we can see all configuration is done, now let’s if our webpage is running properly or not.

Yes! It’s absolutely working.
Not only working it’s also doing Round-Robin.

Conclusion

  • The haproxy config file is dynamic so every time we run the playbook it scan the changes in the inventory & if it found any new managed node it include it as backend server.
  • If you want to do this task on EC2 instances you can do it by configuring the inventory as dynamic. For this configuration you can go to my another blog, link is given below.

Fin.

Finally I want to thank you guys for reading this blog.
Hope you enjoyed the concepts.
If you have any problem in doing the task ask me in the comments.

Thank You !

--

--