diff --git a/conf.d/nginx.conf b/conf.d/nginx.conf deleted file mode 100644 index 92bb22ee8b26954cf6510577af243010fcc3e53d..0000000000000000000000000000000000000000 --- a/conf.d/nginx.conf +++ /dev/null @@ -1,6 +0,0 @@ -server { - listen 3000; - location / { - proxy_pass http://backend:3000; - } -} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 929c2a00d7b34f80e27c86dd3983ba4b2b7f14db..5d6f58f8965709415fc7821d0b2b5683569171bc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3' +version: '3.2' services: frontend: @@ -13,19 +13,31 @@ services: stdin_open: true tty: true depends_on: - - backend + - loadbalancer networks: - letsDo-network - backend: + backend1: + build: + context: server + dockerfile: Dockerfile + env_file: + - .env + restart: always + depends_on: + - database + environment: + - DB_USER + - DB_PASSWORD + networks: + - letsDo-network + + backend2: build: context: server dockerfile: Dockerfile env_file: - .env - # container_name: node-server - # ports: - # - '${BACKEND_PORT}:${BACKEND_PORT}' restart: always depends_on: - database @@ -39,12 +51,13 @@ services: image: mongo container_name: mongo-db - nginx: - image: nginx:latest - volumes: - - ./conf.d:/etc/nginx/conf.d - depends_on: - - backend + loadbalancer: + build: + context: loadbalancer + dockerfile: Dockerfile + links: + - backend1 + - backend2 ports: - ${BACKEND_PORT}:${BACKEND_PORT} networks: diff --git a/loadbalancer/Dockerfile b/loadbalancer/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..c54f47624007d52c678267dc48737ae28b9e5664 --- /dev/null +++ b/loadbalancer/Dockerfile @@ -0,0 +1,7 @@ +FROM nginx + +COPY nginx.conf /etc/nginx/nginx.conf + +EXPOSE 3000 + +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/loadbalancer/nginx.conf b/loadbalancer/nginx.conf new file mode 100644 index 0000000000000000000000000000000000000000..f18eea7a0acf4c733fb444651141f92a46c27881 --- /dev/null +++ b/loadbalancer/nginx.conf @@ -0,0 +1,16 @@ +http { + upstream backend { + server backend1:3000; + server backend2:3001; + } + + server { + listen 3000; + + location / { + proxy_pass http://backend/; + } + } +} + +events {} \ No newline at end of file