load balancer example

This commit is contained in:
bunkerity 2020-10-23 13:57:32 +02:00
parent 222426854e
commit 6a22f7711c
6 changed files with 88 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,5 @@
upstream app {
server app1:3000;
server app2:3000;
server app3:3000;
}

View File

@ -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"]

View File

@ -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}`)
})

View File

@ -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"
}
}

View File

@ -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;
}