Skip to content

Instantly share code, notes, and snippets.

@dragol7
Created September 3, 2017 10:57
Show Gist options
  • Save dragol7/9b14ae15061748eaa616da294553d1e1 to your computer and use it in GitHub Desktop.
Save dragol7/9b14ae15061748eaa616da294553d1e1 to your computer and use it in GitHub Desktop.
Set up for nginx loadbalancer
#!/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