GithubHelp home page GithubHelp logo

meniem / nginx-haproxy-docker Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 16.0 97 KB

Craete HAProxy load balancer for two Nginx web servers using Docker-Compose and Bash scripting

Dockerfile 27.30% Shell 72.70%
docker docker-compose bash-script shell nginx-proxy nginx haproxy haproxy-docker

nginx-haproxy-docker's Introduction

HAProxy load balancer for Nginx servers using Docker

Creates HAProxy load balancer for two Nginx web servers using Docker containers and Bash script. The script will create and configure 3 servers, one load balancer, and two Nginx web servers. HAProxy will be installed on on a single server and then install Nginx web server on the other 2 servers, and HAProxy will act as a load balancer for the Nginx web servers. All of the 3 servers will be containerized using Dockerfile and Docker-Compose.

HAProxy will run in Layer 4 TCP mode, and will forward the RAW TCP packets from the client to the application servers, all the requests go to HAProxy container, and HAProxy will call either the first Nginx or the second one.

Prerequisites:

  • Docker.
  • Docker Compose.
  • Pulling Nginx and HAProxy images form Docker Hub.

Technical details:

  • Docker network subnet is: 172.16.0.0/24
  • HAProxy load balancer IP address is: 172.16.0.2
  • Nginx web server 1 IP address: 172.16.0.10
  • Nginx web server 2 IP address: 172.16.0.20
  • Exposed port for Nginx and HAProxy is: 80 The above information is saved inside the .env file

Repo structure:

N|Solid

Installation steps:

  • Clone the repo
  • Run the script (as sudo) from the main script “script.sh” file:
cd nginx-haproxy-docker
chmod a+x script.sh
./script.sh
  • The script will install docker and docker-compose, then execute the docker-compose which will build and start the three servers.
  • Test the load balancer by executing some random curl commands on the HAProxy IP to check the response from both web servers
curl 172.16.0.2
  • Benchmark the web servers by sending a punch of requests directly:
ab -n 3000 -c 20 http://172.16.0.2/

nginx-haproxy-docker's People

Contributors

meniem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.