> For the complete documentation index, see [llms.txt](https://docs.fylr.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fylr.io/for-system-administrators/installation/linux-docker-compose/multiple-fylrs-in-one-linux.md).

# multiple fylrs in one Linux

Arrange docker and a reverse proxy to avoid conflicts with multiple fylrs

Our default recommended fylr Installation has one fylr directly listening to port 443/80 for http(s). If you want multiple fylrs you need to direct web traffic to the correct one. We present one example here with Apache webserver used as reverse proxy.

{% hint style="info" %}
This increases the risk to run into resource and performance issues (except for small fylr instances with few traffic on a big server).
{% endhint %}

To somewhat reduce performance issues, only one indexer and only one PostgreSQL is used for all fylrs in this example.

## Prerequisites

* install [docker](https://docs.docker.com/engine/install/#server)
* install [certbot](https://certbot.eff.org/)\
  e.g. for Debian 12:\
  `apt install -y snapd`

  log out and back in again, to ensure snap’s paths are updated correctly\
  `snap install snapd`\
  `apt-get remove certbot`\
  `snap install --classic certbot`\
  `type -a certbot || ln -s /snap/bin/certbot /usr/local/bin/`
* install Apache 2\
  e.g. for Debian 12: `apt-get install -y apache2 ; a2enmod ssl rewrite proxy_http`

## Prepare Linux for fylr

We assume `bash` and Debian 12 in our examples.

```
mkdir /srv/fylr ; cd /srv/fylr
echo "vm.max_map_count=262144" >> /etc/sysctl.d/99-memory_for_indexer.conf
sysctl -p /etc/sysctl.d/99-memory_for_indexer.conf
mkdir -p postgres indexer sqlbackups
chown  999 postgres sqlbackups
chown 1000 indexer
swapoff -a; free -h
```

## Download all and configure common services

Use the following `docker-compose.yml` as a starting point:

```
curl https://raw.githubusercontent.com/programmfabrik/fylr-gitbook/main/_assets/multi/docker-compose.yml -o docker-compose.yml
```

Replace all strings that have `EXAMPLE` in it. E.g. with vim: `vim docker-compose.yml`

Download all software and start the indexer and SQL database service:

```
docker compose pull
docker compose up -d postgresql opensearch
```

## For each fylr instance

Do all the rest of the instructions for the first fylr instance. Then repeat all of it for the second.

Choose unique names and ports and put them into bash variables. Use the same as you used in `docker-compose.yml`.

```
DIR=fylr-EXAMPLE1     # directory name below /srv/fylr/
SERVICE=fylr-EXAMPLE1 # name in docker-compose.yml
DOMAIN=EXAMPLE1.COM
PORT=81
DB=EXAMPLE1
DBUSER=EXAMPLE1
```

#### Configure the reverse proxy:

```
cd /etc/apache2/sites-enabled
cat >>../sites-available/$DOMAIN.conf<<EOF
<VirtualHost *:80>
    ServerName $DOMAIN
    ServerAdmin administratoren@programmfabrik.de
    ProxyPreserveHost On
    RequestHeader unset X-Real-IP
    ProxyPass / http://127.0.0.1:$PORT/ upgrade=websocket
    ProxyPassReverse / http://127.0.0.1:$PORT/ upgrade=websocket
</VirtualHost>
EOF
ln -s ../sites-available/$DOMAIN.conf .
a2enmod headers
apache2ctl -t && systemctl restart apache2
certbot --apache --agree-tos -d $DOMAIN # -m emailadress
```

... certbot in the last command will configure the https part of the reverse proxy in Apache.

#### Configure fylr:

```
cd /srv/fylr
mkdir -p $DIR/config/fylr $DIR/assets $DIR/migration $DIR/backups
chown 1000 $DIR/assets $DIR/backups $DIR/migration
curl https://raw.githubusercontent.com/programmfabrik/fylr-gitbook/main/_assets/multi/fylr.yml -o $DIR/config/fylr/fylr.yml
vi $DIR/config/fylr/fylr.yml  # replace string with EXAMPLE
```

Replace all strings in `fylr.yml` that have `EXAMPLE` in it. E.g. with vim:\
`vim $DIR/config/fylr/fylr.yml`

{% hint style="warning" %}
*From version 6.35.0*: fylr uses the client address Apache forwards only from a peer listed in `fylr.trustedProxies`. Inside the container, Apache connects from the gateway of the container's docker network (`docker network inspect <network>`, field `Gateway`). Add it to `fylr.yml`:

```yaml
fylr:
  trustedProxies:
    - "172.18.0.1" # the gateway address shown by docker network inspect
```

Without it every request looks as if it came from the proxy: IP subnet filters, the failed-login lockout and the audit log see the proxy's address, and fylr logs a warning naming it.

`RequestHeader unset X-Real-IP` in the virtual host is required: fylr reads `X-Real-IP` before `X-Forwarded-For`, and Apache only appends to `X-Forwarded-For`, so it would pass on an `X-Real-IP` sent by the caller.
{% endhint %}

#### Create SQL database:

```
PSQL="docker compose exec postgresql psql -U fylr"
$PSQL -c 'CREATE DATABASE "'$DB'";'

$PSQL -c "CREATE USER $DBUSER WITH LOGIN ENCRYPTED PASSWORD '$DBUSER';"

$PSQL -c 'GRANT ALL PRIVILEGES ON DATABASE '$DB' TO '$DBUSER';'

$PSQL -c 'ALTER DATABASE '$DB' OWNER TO '$DBUSER';'
```

#### Start this fylr instance:

```
docker compose up -d $SERVICE
```

Repeat for each additional fylr instance the whole part from "For each fylr instance" to here.

## Remarks

A maintain script and cron job, as in the [default recommended installation](/for-system-administrators/installation/linux-docker-compose.md), are not provided by us, as we do not have sufficient experience with this multi-fylr-setup. Use the recommended installation instead, when possible.
