# Конфигурационный файл

Часть основных настроек можно задать через конфигурационный файл в yaml формате.

## Путь по умолчанию

В Windows обычно файл хранится по пути - `$env:USERPROFILE\AppData\Local\tuna\tuna.yml`,<br />в Unix-подобных операционных системах (macOS, Linux, FreeBSD) - `${HOME}/.config/tuna/tuna.yml`.

## Сохранение основных настроек

Часть настроек можно определить специальными командами:

Сохранить токен:

```shell
tuna config save-token <ваш_токен>

```

Задать [регион](https://tuna.am/docs/tunnels/guides/locations.md):

```shell
tuna config save-location nl

```

Задать [API-ключ](https://tuna.am/docs/guides/api.md):

```shell
tuna config save-api-key <ваш_api_key>

```

## Пример файла

Пример основных настроек:

```yaml
---
version: "1"
token: tt_***
apiKey: tak_***
location: nl
inspectAddr: "0.0.0.0"

```

## Использование иного пути к файлу

Можно явно указывать путь к файлу с помощью флага `--config`:

```shell
tuna --config /tmp/tuna.yml http 8080

```

Или через переменную окружения `TUNA_CONFIG`:

```shell
export TUNA_CONFIG=/tmp/tuna.yml
tuna http 8080

```

## Множественный запуск туннелей

В файле может хранится описание для [множественного запуска](https://tuna.am/docs/tunnels/guides/multi-tunnels.md) туннелей, пример:

```yaml
---
tunnels:
  web:
    tags: [frontend, ui]
    commandLine: tuna http localhost:5173 --subdomain=web
  php:
    tags: [backend, php, api]
    commandLine: tuna http 8080 --subdomain=api
  python:
    tags: [backend, python, api]
    commandLine: tuna http 9000 --subdomain=new-api
  postgres:
    tags: db
    commandLine: tuna tcp 5432 --port=postgres
  mysql:
    tags: db
    commandLine: tuna tcp 3306 --port=mysql

```

## Политики трафика

В файле может хранится описание правил для [политик трафика](https://tuna.am/docs/traffic-policy.md), пример:

```yaml
---
rules:
  - name: robots.txt
    expressions:
      - hasPrefix(req.URL.Path, "/robots.txt")
    actions:
      - name: шаг 1
        type: custom_response
        config:
          statusCode: 200
          content: |
            User-agent: *
            Disallow: /
          headers:
            content-type: "text/plain"
  - name: Мок для банков
    expressions:
      - hasPrefix(req.URL.Path, "/banks")
    actions:
      - type: custom_response
        config:
          statusCode: 403
          content: |
            Запрещено
          headers:
            content-type: "text/plain; charset=utf-8"
  - expressions:
      - hasPrefix(req.URL.Path, "/v1")
    actions:
      - type: reverse_proxy
        config:
          url: "http://127.0.0.1:7070"

```

## Проверка корректности синтаксиса

```shell
tuna config check

```
