# Configuration

> Environment variables and reverse proxy settings for a self-hosted tiko.

Everything works without a `.env` file. To override defaults, copy [`.env.example`](https://github.com/tiko-run/tiko/blob/main/.env.example) to `.env` next to the compose file and edit it.

The refresh interval is set in **Settings → Task source**, not in the environment.

## Variables

### Sign-in and secrets

| Variable | Purpose | Default |
|---|---|---|
| `TIKO_PASSWORD` | Password of the first account, `admin`. When empty, one is generated on first start, printed once to the API log and saved to `data/password`. Not read once the account exists | generated |
| `TIKO_SECRET_KEY` | Encrypts tracker tokens at rest; needed only to connect a tracker (`openssl rand -base64 32`) | unset |

### Task source

| Variable | Purpose | Default |
|---|---|---|
| `TIKO_TRACKER` | Tracker for everyone: `demo` or `jira`. Set, **Settings → Task source** shows it read-only | set in Settings |
| `JIRA_BASE_URL` | Jira URL for everyone, like `https://jira.example.com`; a wrong URL stops the start. Each person still adds their own token | set in Settings |
| `JIRA_TLS_VERIFY` | Verify Jira's TLS certificate; `false` skips the check | `true` |
| `JIRA_CA_BUNDLE` | Path inside the container to a CA bundle for a corporate certificate authority | unset |
| `GITHUB_TOKEN` | Read-only GitHub token that raises the request limit for public issues from 60 to 5000 an hour, so GitHub cards update at the board's pace. See [GitHub Issues](https://docs.tiko.run/github-issues/) | unset |

To trust a corporate CA, put the bundle in `./data` (for example `data/corp-ca.pem`) and set `JIRA_CA_BUNDLE=data/corp-ca.pem`.

### Limits and the demo

| Variable | Purpose | Default |
|---|---|---|
| `TIKO_DEMO` | `1` lets anyone start without an account as a demo visitor on the demo tasks, and sign up to stay. See [Running a demo](https://docs.tiko.run/demo/) | off |
| `TIKO_DEMO_LIMIT` | Demo visitors the instance keeps at once | `500` |
| `TIKO_BOARD_LIMIT` | Boards a person may own, admins and demo visitors aside | no limit |
| `TIKO_FILES_QUOTA_MB` | Megabytes of pictures a workspace may keep, copies included. See [Pictures](https://docs.tiko.run/data-and-upgrades/#pictures) | no limit; 20 on a demo |
| `TIKO_CALDAV_PRIVATE_NETWORK` | `deny` stops people from connecting a CalDAV server on a private network, such as one at home. A public instance should set it. See [CalDAV tasks](https://docs.tiko.run/caldav/#a-server-on-your-home-network) | `allow`; `deny` on a demo |

### Database

| Variable | Purpose | Default |
|---|---|---|
| `POSTGRES_PASSWORD` | Password of Postgres in the `db` service; the installers write a random one. Read once, when the volume is made, so a new value later locks tiko out. Letters and digits only | `tiko-local` |
| `DATABASE_URL` | A Postgres server of your own instead of the `db` service. See [Your own Postgres server](https://docs.tiko.run/data-and-upgrades/#your-own-postgres-server) | the `db` service |

### Ports, processes and proxies

| Variable | Purpose | Default |
|---|---|---|
| `TIKO_PORT` | Port on your machine that Docker Compose gives the web UI | `3000` |
| `TIKO_API_PORT` | Port on your machine for the API when you run from source with `docker compose up`, open to this machine only. The release compose file does not publish the API | `8000` |
| `TIKO_WORKERS` | API processes, one core each. Set it for both containers, as the compose files do. See [Several processes](#several-processes) | `1` |
| `TIKO_SOCKET_DIR` | A directory shared by both containers; the web container reaches the API over Unix sockets in it. See [A Unix socket between the containers](#a-unix-socket-between-the-containers) | empty: the network |
| `TIKO_TRUSTED_PROXIES` | Proxies in front of tiko whose word on the client's address the web container takes, as comma-separated networks. See [The client's address](#the-clients-address) | private networks |
| `TIKO_CLIENT_IP_HEADER` | The header those proxies put the client's address in | `X-Forwarded-For` |

### Monitoring and logs

| Variable | Purpose | Default |
|---|---|---|
| `TIKO_METRICS_TOKEN` | Lets a monitoring system read `/metrics` with `Authorization: Bearer <token>`. See [Monitoring](https://docs.tiko.run/monitoring/) | unset, admins only |
| `TIKO_METRICS_PORT` | A second port that serves `/metrics` to the token from its own thread, so it answers while the instance is overloaded. See [Monitoring](https://docs.tiko.run/monitoring/) | unset, no second port |
| `LOG_LEVEL` | Log level | `info` |
| `APP_ENV` | Environment name: `local`, `stage` or `production` | `local` |

### Updates, usage stats and error reports

| Variable | Purpose | Default |
|---|---|---|
| `UPDATE_CHECK` | Ask GitHub every 30 minutes for new releases to show "update available" in About, and how much the update matters; `false` turns it off | `true` |
| `TIKO_USAGE_STATS` | Daily usage counts without personal data, listed in [Usage stats](https://docs.tiko.run/privacy/). `false` turns them off and locks the switch in **Settings → Privacy**; unset, an admin decides there | unset (on) |
| `TIKO_STATS_URL` | Where the usage stats go, for your own collector; see [Usage stats](https://docs.tiko.run/privacy/#closed-networks-and-your-own-collector) | `https://t.tiko.run/v1/events` |
| `TIKO_ERROR_REPORTS` | Error reports, see [Error reports](https://docs.tiko.run/privacy/#error-reports). `true` turns them on, `false` off; either locks the switch in **Settings → Privacy** | unset (off) |
| `TIKO_ERROR_REPORTS_DSN` | Where error reports go: your own Sentry DSN instead of ours. `TIKO_ERROR_REPORTS=false` keeps the Sentry client from starting at all | the tiko project's Sentry (EU) |
| `TIKO_DEPLOY` | How tiko runs, reported in the usage stats; the installer sets `installer`, Railway and Render are found on their own | unset (`compose`) |
| `TIKO_HOST_OS` | The system tiko was installed on, reported in the usage stats: `linux`, `darwin`, `windows` or `other`. The installer sets it, since inside a container tiko sees only Linux | unset |

## Behind your own reverse proxy

Live boards use a WebSocket at `/api/boards/<id>/live`, on the same address as the rest of tiko. The proxy in front of tiko has to:

- pass WebSocket upgrades to the web container (port 3000);
- keep idle connections open;
- keep the `Host` header as the browser sent it: tiko refuses a live connection whose page address differs from the host it was asked for.

Without that, boards open view-only with "Live connection unavailable". Public links use `/api/public/<token>/live/<room>` the same way and fall back to checking for changes every few seconds.

Railway, Render and plain `docker compose` need no changes. Caddy and Traefik pass WebSockets and the visitor's address without extra settings; nginx needs the upgrade headers, the visitor's address and a longer read timeout:

**Caddy**

```text
tiko.example.com {
    reverse_proxy localhost:3000
}
```

**nginx**

```nginx
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    server_name tiko.example.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        # The visitor's address, set anew so a client cannot add one of its own.
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_read_timeout 1h;
        # Pictures on boards are up to 25 MB; nginx takes 1 MB by default.
        client_max_body_size 26m;
    }
}
```

### The client's address

tiko counts sign-in attempts, new demo visitors and the pictures guests of a public link load by the client's address. The web container takes it from the proxy in front only when that proxy is one it trusts. By default that is a proxy on a private network, the usual case for a reverse proxy on the same host or in the same Docker network, which puts the address in `X-Forwarded-For`.

Set both variables on the web container when tiko sits behind something else:

| In front of tiko | `TIKO_TRUSTED_PROXIES` | `TIKO_CLIENT_IP_HEADER` |
|---|---|---|
| A reverse proxy on the same host or network | leave empty | leave empty |
| Railway | `0.0.0.0/0,::/0` | leave empty |
| Cloudflare, straight to your server | Cloudflare's networks, see below | `CF-Connecting-IP` |

> **Caution: Trust everything only on Railway**
>
> Railway's edge writes `X-Forwarded-For` itself and drops what the client sent, so every hop in it can be believed. Trust everything only where the platform does that: anywhere else a client could name any address.

Cloudflare publishes its networks; join them into the variable:

```bash
echo "TIKO_TRUSTED_PROXIES=$(curl -fsS https://www.cloudflare.com/ips-v4 https://www.cloudflare.com/ips-v6 | paste -sd, -)"
```

- **Refresh** the list when Cloudflare announces a change; it changes now and then.
- **Keep the server reachable only through Cloudflare**, or a client that reaches it directly can send `CF-Connecting-IP` too.
- **A bad value** stops the web container with a line that names it.

To check, sign in from two networks and look at the web container's log: each request starts with the client's address, not the proxy's.

## Several processes

One API process uses one core, so an instance with many busy boards stops at what one core can serve. `TIKO_WORKERS=4` starts four processes in the API container, on ports 8000 to 8003:

```bash
# .env
TIKO_WORKERS=4
```

A board is open in exactly one of them, the one its id names, and the web container sends everything about that board there. Requests that are about no board go to any of them.

- **Both containers need the number:** the API to start the processes, the web container to pick one. The compose files pass it to both. On Render or Railway, set it on both services.
- **Go through the web container** (port 3000), as with one process. A socket that reaches the wrong process is closed and the tab tries again, so a proxy of your own that talks to port 8000 directly only works with one process.
- **Nothing else changes:** signing out, role changes and the limits on wrong passwords and on public links work across the processes as they do in one.
- **Together:** the processes stand and fall together; when one stops, the container restarts.
- **Database connections:** each process keeps up to 6 connections to Postgres, and the `db` service takes 100. With more than 16 processes, raise `max_connections` in its `command`.

## A Unix socket between the containers

On one host the web container can reach the API over a Unix socket instead of the Docker network. In our measurement both containers used about a tenth less CPU on busy boards. It is off unless you turn it on, and it needs a directory that both containers see:

```yaml
# docker-compose.override.yml
services:
  api:
    environment:
      TIKO_SOCKET_DIR: /run/tiko
    volumes: ["sockets:/run/tiko"]
  web:
    environment:
      TIKO_SOCKET_DIR: /run/tiko
    volumes: ["sockets:/run/tiko"]
volumes:
  sockets:
```

The API keeps its ports as well, so health checks and metrics work as before. Platforms that run the two services apart, like Render and Railway, have no shared directory: leave it off there.
