Created
September 3, 2017 10:57
-
-
Save dragol7/9b14ae15061748eaa616da294553d1e1 to your computer and use it in GitHub Desktop.
Set up for nginx loadbalancer
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
#!/bin/bash | |
echo 'Starting Provision: loadbalancer' | |
sudo apt-get update | |
sudo apt-get install -y nginx | |
sudo service nginx stop | |
sudo rm -rf /etc/nginx/sites-available/default | |
sudo rm -rf /etc/nginx/sites-enabled/default | |
sudo touch /etc/nginx/sites-enabled/default | |
echo "upstream backend { | |
server 192.168.30.11 max_fails=2 fail_timeout=20s; | |
server 192.168.30.12 weight=2 max_fails=2 fail_timeout=20s; | |
} | |
server { | |
listen 80 default_server; | |
# listen [::]:80 default_server ipv6only=on; | |
root /usr/share/nginx/html; | |
index index.html index.htm; | |
server_name $1 www.$1; | |
location / { | |
proxy_pass http://backend; | |
} | |
location ~* \.(gif|jpg|png)$ { | |
expires 30d; | |
add_header Cache-Control 'public'; | |
} | |
}" >> /etc/nginx/sites-enabled/default | |
sudo service nginx start | |
echo "Machine: loadbalancer" >> /usr/share/nginx/html/index.html | |
echo '*************** Provision loadbalancer complete ***************' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment