Skip to content

Commit

Permalink
improve nginx config
Browse files Browse the repository at this point in the history
  • Loading branch information
BenLubar committed May 31, 2016
1 parent 4336ab5 commit f4aecd9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
11 changes: 1 addition & 10 deletions nginx-config-example
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
upstream nodebb {
ip_hash;

server 172.21.1.253:4567;
server 172.21.1.253:4568;
server 172.21.1.254:4567;
server 172.21.1.254:4568;

keepalive 16;
}
include /etc/nginx/nodebb-upstream.conf;

server {
server_name nodebb.local;
Expand Down
10 changes: 10 additions & 0 deletions nodebb-upstream.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
upstream nodebb {
ip_hash;

server 172.21.1.253:4567 down;
server 172.21.1.253:4568 down;
server 172.21.1.254:4567;
server 172.21.1.254:4568;

keepalive 16;
}
7 changes: 5 additions & 2 deletions setup.bash
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/bin/bash -e

# add the nginx config file
sudo cp nodebb-upstream.conf /etc/nginx/

# make sure we have Docker
which docker &> /dev/null || curl -sSL https://get.docker.com/ | sh

# build the NodeBB container
docker build -t boomzillawtf/tdwtf .
# pull the NodeBB image
docker pull boomzillawtf/tdwtf

# create a Docker network
docker network create --subnet 172.21.1.0/24 wtdwtf
Expand Down
10 changes: 8 additions & 2 deletions update.bash
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/bin/bash -e

# build the new image
docker build -t boomzillawtf/tdwtf .
# pull the new image
docker pull boomzillawtf/tdwtf

# rename the old image
docker rename wtdwtf-nodebb wtdwtf-nodebb-temp

# flip-flop IP addresses so we can let nginx handle the switchover
ip=172.21.1.254
other_ip=172.21.1.253
if [[ "`docker inspect -f '{{ .NetworkSettings.Networks.wtdwtf.IPAddress }}' wtdwtf-nodebb-temp`" == "172.21.1.254" ]]; then
ip=172.21.1.253
other_ip=172.21.1.254
fi

# start the new NodeBB container
Expand All @@ -19,6 +21,10 @@ docker run -d --name wtdwtf-nodebb --net wtdwtf --ip $ip --restart unless-stoppe
until nc -z $ip 4567; do echo Waiting for NodeBB; sleep 1; done
until nc -z $ip 4568; do echo Waiting for NodeBB; sleep 1; done

# switch nginx upstream
sudo sed -i /etc/nginx/nodebb-upstream.conf -e "s/\\(server $ip:[0-9]\\+\\) down;/\\1;/" -e "s/\\(server $other_ip:[0-9]\\+\\);/\\1 down;/"
sudo /etc/init.d/nginx reload

# remove the old container
docker stop wtdwtf-nodebb-temp
docker rm wtdwtf-nodebb-temp

0 comments on commit f4aecd9

Please sign in to comment.