#1232: 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.

Preparing Swarmica
- In the file
/root/swarmica/.env, add the addresses of the load balancers to theDJANGO_ALLOWED_HOSTSvariable:
DJANGO_ALLOWED_HOSTS=my.swarmica.tld,balancer1.swarmica.tld,balancer2.swarmica.tld
- In the file
/root/swarmica/docker-compose.yml, wherever theHostdirective is used, add the addresses of the load balancers, for example, like this:
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.
- Restart the services:
sudo su -
cd /root/swarmica
docker compose down
docker compose up -d
Load Balancer Settings (nginx)
-
First, install and configure nginx on each load balancer.
-
Get SSL certificates for the domain names and add them to the nginx configuration.
-
In the
serverdirective of the site (virtual host) that handles the domain name of the load balancer, replace the section responsible forlocation /,so that you get the following configuration:
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;
}
}
- Restart nginx:
invoke-rc.d nginx restart
- 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