-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
25
0x0F-load_balancer/2-puppet_custom_http_response_header.pp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Load balancer |