Skip to content

Commit

Permalink
Added project 0x0F
Browse files Browse the repository at this point in the history
  • Loading branch information
Baribor committed Dec 28, 2023
1 parent 83896db commit fdab212
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 0x0F-load_balancer/0-custom_http_response_header
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
# Configure Nginx so that its HTTP response contains a custom header
# HTTP response contains a custom header (on web-01 and web-02)
var=$(hostname)
new_string="error_page 404 \/custom_404.html;\n location \/redirect_me {\n return 301 \$scheme:\/\/www.google.com;"
new_string2="server {\n\tadd_header X-Served-By $var;"

apt-get update -y
apt-get install nginx -y
echo "Hello World!" > /usr/share/nginx/html/index.html
mkdir -p /var/www/html
echo "Ceci n'est pas une page" > /var/www/html/custom_404.html
sudo sed -i -E "s/^[^#]+location \/ \{/$new_string/" /etc/nginx/sites-available/default
sudo sed -i -E "s/^server \{/$new_string2/" /etc/nginx/sites-available/default
sudo service nginx start
40 changes: 40 additions & 0 deletions 0x0F-load_balancer/1-install_load_balancer
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
#Installs and configures HAproxy in a load balancer server

apt-get install -y software-properties-common
add-apt-repository -y ppa:vbernat/haproxy-1.8
apt-get update
apt-get install -y haproxy=1.8.\*

echo "ENABLED=1" >> /etc/default/haproxy
mv /etc/haproxy/haproxy.cfg{,.original}
touch /etc/haproxy/haproxy.cfg

printf %s "global
log 127.0.0.1 local0 notice
maxconn 2000
user haproxy
group haproxy
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
timeout connect 5000
timeout client 10000
timeout server 10000
listen hbnb
bind 0.0.0.0:80
mode http
stats enable
stats uri /haproxy?stats
balance roundrobin
option httpclose
option forwardfor
server 356520-web-01 54.89.27.149:80 check
server 356520-web-02 100.25.152.185:80 check
" >> /etc/haproxy/haproxy.cfg

service haproxy start
25 changes: 25 additions & 0 deletions 0x0F-load_balancer/2-puppet_custom_http_response_header.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Installs a Nginx server with custom HTTP header

exec {'update':
provider => shell,
command => 'sudo apt-get -y update',
before => Exec['install Nginx'],
}

exec {'install Nginx':
provider => shell,
command => 'sudo apt-get -y install nginx',
before => Exec['add_header'],
}

exec { 'add_header':
provider => shell,
environment => ["HOST=${hostname}"],
command => 'sudo sed -i "s/include \/etc\/nginx\/sites-enabled\/\*;/include \/etc\/nginx\/sites-enabled\/\*;\n\tadd_header X-Served-By \"$HOST\";/" /etc/nginx/nginx.conf',
before => Exec['restart Nginx'],
}

exec { 'restart Nginx':
provider => shell,
command => 'sudo service nginx restart',
}
1 change: 1 addition & 0 deletions 0x0F-load_balancer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Load balancer

0 comments on commit fdab212

Please sign in to comment.