---
# System prepended metadata

title: Lab 10. System and Network administartion

---

# Lab 10. System and Network administartion
## Timur Mustafin

# Load balancing with nginx

### Load balancer
#### Nginx config 

```
http {
    upstream myapp1 {
        server node1;
        server node2;
    }

    server {
        listen 80;

        location / {
            proxy_pass http://myapp1;
        }
    }
}
events {}

```

#### Dockerfile

```
FROM nginx:latest

COPY nginx.conf /etc/nginx/nginx.conf

```

### Node
#### Nginx
uses default config (serves default page)

#### Dockerfile

```
FROM nginx:latest
```

#### docker-compose

```
version: "3"
services:
  node1:
    build: .
    ports:
      - 80
    networks:
      - internal

  node2:
    build: .
    ports:
      - 80
    networks:
      - internal

  nginx:
    build: nginx/
    ports:
      - 80:80
    networks:
      - internal


networks:
  internal:

```

## Verification 
start the service, both nodes are working

![](https://i.imgur.com/ewcGx6J.png)

Destroy one node with `docker stop`
![](https://i.imgur.com/p4oXasO.png)

After a few 499(i updated the page in a browser) it always uses one node with normal 344 response 
![](https://i.imgur.com/0BybrT3.jpg)


