diff --git a/examples/load-balancer/docker-compose.yml b/examples/load-balancer/docker-compose.yml new file mode 100644 index 00000000..ea1dd251 --- /dev/null +++ b/examples/load-balancer/docker-compose.yml @@ -0,0 +1,39 @@ +version: '3' + +services: + + myreverse: + image: bunkerity/bunkerized-nginx + restart: always + ports: + - 80:80 + - 443:443 + volumes: + - ./letsencrypt:/etc/letsencrypt + - ./http-confs:/http-confs + - ./server-confs:/server-confs + environment: + - SERVER_NAME=www.website.com # replace with your domain + - SERVE_FILES=no + - DISABLE_DEFAULT_SERVER=yes + - REDIRECT_HTTP_TO_HTTPS=yes + - AUTO_LETS_ENCRYPT=yes + + app1: + build: js-app + restart: always + environment: + - NODE_ENV=production + + app2: + build: js-app + restart: always + environment: + - NODE_ENV=production + + app3: + build: js-app + restart: always + environment: + - NODE_ENV=production + diff --git a/examples/load-balancer/http-confs/upstream.conf b/examples/load-balancer/http-confs/upstream.conf new file mode 100644 index 00000000..4e8d6cbf --- /dev/null +++ b/examples/load-balancer/http-confs/upstream.conf @@ -0,0 +1,5 @@ +upstream app { + server app1:3000; + server app2:3000; + server app3:3000; +} diff --git a/examples/load-balancer/js-app/Dockerfile b/examples/load-balancer/js-app/Dockerfile new file mode 100644 index 00000000..760e7293 --- /dev/null +++ b/examples/load-balancer/js-app/Dockerfile @@ -0,0 +1,11 @@ +FROM node + +COPY app/ /home/node/app + +RUN cd /home/node/app && npm install && chown -R root:node /home/node/app && chmod -R 770 /home/node/app + +WORKDIR /home/node/app + +USER node + +CMD ["node", "index.js"] diff --git a/examples/load-balancer/js-app/app/index.js b/examples/load-balancer/js-app/app/index.js new file mode 100644 index 00000000..4b197787 --- /dev/null +++ b/examples/load-balancer/js-app/app/index.js @@ -0,0 +1,13 @@ +const express = require('express') +const app = express() +const port = 3000 +var os = require("os"); + +app.get('/', (req, res) => { + res.send('Container id = ' + os.hostname()) +}) + +app.listen(port, () => { + console.log(`Example app listening at http://localhost:${port}`) +}) + diff --git a/examples/load-balancer/js-app/app/package.json b/examples/load-balancer/js-app/app/package.json new file mode 100644 index 00000000..8f2840d4 --- /dev/null +++ b/examples/load-balancer/js-app/app/package.json @@ -0,0 +1,14 @@ +{ + "name": "js-app", + "version": "1.0.0", + "description": "demo", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "express": "^4.17.1" + } +} diff --git a/examples/load-balancer/server-confs/reverse-proxy.conf b/examples/load-balancer/server-confs/reverse-proxy.conf new file mode 100644 index 00000000..d0842d13 --- /dev/null +++ b/examples/load-balancer/server-confs/reverse-proxy.conf @@ -0,0 +1,6 @@ +proxy_set_header Host $host; +proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + +location / { + proxy_pass http://app$request_uri; +}