# Is it possible to maintain Russian and foreign circuits as a single scheme?
# Symptoms

Configuration with multiple load balancers.
It is necessary to set up two or more showcases that will be located in different geographical locations and with different domain names that will go to the same Swarmica instance. How can this be done?

# Solution

This article provides a solution for two external nginx load balancers; by analogy, the solution can be applied to a different number and types of load balancers.

![](https://support.swarmica.com/attachments/v/R/vRH4xYujiLYMF1NC_a/L7_Balancer.jpg)

### Preparing Swarmica

1. In the file `/root/swarmica/.env`, add the addresses of the load balancers to the `DJANGO_ALLOWED_HOSTS` variable:

```txt
DJANGO_ALLOWED_HOSTS=my.swarmica.tld,balancer1.swarmica.tld,balancer2.swarmica.tld
```

2. In the file `/root/swarmica/docker-compose.yml`, wherever the `Host` directive is used, add the addresses of the load balancers, for example, like this:

```yaml
services:

  frontend:
    image: reg.gl.swd.im/swarmica/frontend:${SW_FRONTEND_VERSION}
    depends_on:
      - django
    restart: always
    volumes:
      - ./robots.txt:/robots.txt:ro
      - swarmica_static:/admin_static:ro
      - swarmica_ugc:/attachments:ro
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.nginx.entrypoints=web-secure"
      - "traefik.http.routers.nginx.rule=Host(`{SW_HOSTNAME}`) || Host(balancer1.swarmica.tld) || Host(balancer2.swarmica.tld)"
      - "traefik.http.routers.nginx.tls.certresolver=letsencrypt"
      - "traefik.http.routers.nginx.middlewares=secure-headers,compression"
      - "traefik.http.routers.nginx.priority=10"
```

Typically, this needs to be done for the `frontend`, `django`, `django-websocket`, `helpcenter` services.

3. Restart the services:

```bash
sudo su -
cd /root/swarmica
docker compose down
docker compose up -d
```

### Load Balancer Settings (nginx)

1. First, install and configure nginx on each load balancer.

2. Get SSL certificates for the domain names and add them to the nginx configuration.

3. In the `server` directive of the site (virtual host) that handles the domain name of the load balancer, replace the section responsible for `location /,` so that you get the following configuration:

```txt
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        listen 443 ssl;
        server_name balancer1.swarmica.tld;

        ssl_certificate /etc/nginx/ssl/balancer1.swarmica.tld.crt;
        ssl_certificate_key /etc/nginx/ssl/balancer1.swarmica.tld.key;

        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_ciphers HIGH:aNULL:MD5;

        root /var/www/html;

        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                proxy_pass              https://my.swarmica.tld;
                proxy_set_header        Host    $host;
                proxy_set_header        X-Forwarded-For $remote_addr;
                add_header              X-Upstream      $upstream_addr;
        }
}
```

4. Restart nginx:

```bash
invoke-rc.d nginx restart
```

5. If different brands are to be used, then the brand can be specified through a header in the load balancers:

```
proxy_set_header     X-Swarmica-Brand: UID
```