> ## Documentation Index
> Fetch the complete documentation index at: https://tyk.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Tyk Edge Gateway Environment Variables

> Environment variables and configuration options for Tyk Edge Gateway.

This page details the environment variables that can be used to configure the Tyk Edge Gateway.

## Configuration

Tyk Edge Gateway (Edge Gateway) is configured primarily using environment variables.

### Configuration Precedence

The application loads configuration in the following order of precedence (highest to lowest):

1. **Shell Environment Variables**: Variables set in the OS/Shell (e.g., `export PORT=9090`) always override everything else.
2. **`.env` File**: Variables loaded from the file specified by the `-env` flag.
   * *Note:* The application checks if a variable is already set in the environment before loading it from the file, ensuring shell variables are preserved.

### Command Line Flags

You can specify a `.env` file using the `-env` flag when starting the binary:

```bash theme={null}
./microgateway -env /path/to/prod.env
```

### Supported Formats

* **Main Configuration**: Only the `.env` format (key=value pairs) is supported via the `-env` flag.
* **Plugin Configuration**: Supports JSON and YAML files for plugin definitions, specified via the `PLUGINS_CONFIG_PATH` environment variable.

### Environment Variable Type Mapping

When configuring Tyk components using environment variables, it's important to understand how different data types are represented. The type of each variable is based on its definition in the Go source code. This section provides a guide on how to format values for common data types.

| Go Type                  | Environment Variable Format                | Example                                                              |
| ------------------------ | ------------------------------------------ | -------------------------------------------------------------------- |
| `string`                 | A regular string of text.                  | `TYK_GW_SECRET="mysecret"`                                           |
| `int`, `int64`           | A whole number.                            | `TYK_GW_LISTENPORT=8080`                                             |
| `bool`                   | `true` or `false`.                         | `TYK_GW_USEDBAPPCONFIG=true`                                         |
| `[]string`               | A comma-separated list of strings.         | `TYK_PMP_PUMPS_STDOUT_FILTERS_SKIPPEDAPIIDS="api1,api2,api3"`        |
| `map[string]string`      | A comma-separated list of key:value pairs. | `TYK_GW_GLOBALHEADERS="X-Tyk-Test:true,X-Tyk-Version:1.0"`           |
| `map[string]interface{}` | A JSON string representing the object.     | `TYK_GW_POLICIES_POLICYSOURCE_CONFIG='{"connection_string": "..."}'` |

<Note>
  For complex types like `map[string]interface{}`, the value should be a valid JSON string. For `[]string` and `map[string]string`, ensure there are no spaces around the commas unless they are part of the value itself.
</Note>

## Variables

### PORT

ENV: <b>PORT</b><br />
Type: `integer`<br />
Default: `8080`<br />

The port for the server to listen on.

### HOST

ENV: <b>HOST</b><br />
Type: `string`<br />
Default: `0.0.0.0`<br />

The host for the server to bind to.

### TLS\_ENABLED

ENV: <b>TLS\_ENABLED</b><br />
Type: `boolean`<br />
Default: `false`<br />

Enable TLS.

### TLS\_CERT\_PATH

ENV: <b>TLS\_CERT\_PATH</b><br />
Type: `string`<br />

The path to the TLS certificate file.

### TLS\_KEY\_PATH

ENV: <b>TLS\_KEY\_PATH</b><br />
Type: `string`<br />

The path to the TLS key file.

### READ\_TIMEOUT

ENV: <b>READ\_TIMEOUT</b><br />
Type: `string`<br />
Default: `300s`<br />

The read timeout for the server.

### WRITE\_TIMEOUT

ENV: <b>WRITE\_TIMEOUT</b><br />
Type: `string`<br />
Default: `300s`<br />

The write timeout for the server.

### IDLE\_TIMEOUT

ENV: <b>IDLE\_TIMEOUT</b><br />
Type: `string`<br />
Default: `120s`<br />

The idle timeout for the server.

### SHUTDOWN\_TIMEOUT

ENV: <b>SHUTDOWN\_TIMEOUT</b><br />
Type: `string`<br />
Default: `30s`<br />

The shutdown timeout for the server.

### DATABASE\_TYPE

ENV: <b>DATABASE\_TYPE</b><br />
Type: `string`<br />
Default: `sqlite`<br />

The type of database to use (`sqlite` or `postgres`).

### DATABASE\_DSN

ENV: <b>DATABASE\_DSN</b><br />
Type: `string`<br />
Default: `file:./data/microgateway.db?cache=shared&mode=rwc`<br />

The database connection string.

### DB\_MAX\_OPEN\_CONNS

ENV: <b>DB\_MAX\_OPEN\_CONNS</b><br />
Type: `integer`<br />
Default: `25`<br />

The maximum number of open database connections.

### DB\_MAX\_IDLE\_CONNS

ENV: <b>DB\_MAX\_IDLE\_CONNS</b><br />
Type: `integer`<br />
Default: `25`<br />

The maximum number of idle database connections.

### DB\_CONN\_MAX\_LIFETIME

ENV: <b>DB\_CONN\_MAX\_LIFETIME</b><br />
Type: `string`<br />
Default: `5m`<br />

The maximum lifetime of a database connection.

### DB\_AUTO\_MIGRATE

ENV: <b>DB\_AUTO\_MIGRATE</b><br />
Type: `boolean`<br />
Default: `true`<br />

Enable automatic database migrations.

### DB\_LOG\_LEVEL

ENV: <b>DB\_LOG\_LEVEL</b><br />
Type: `string`<br />
Default: `warn`<br />

The log level for the database.

### CACHE\_ENABLED

ENV: <b>CACHE\_ENABLED</b><br />
Type: `boolean`<br />
Default: `true`<br />

Enable caching.

### CACHE\_MAX\_SIZE

ENV: <b>CACHE\_MAX\_SIZE</b><br />
Type: `integer`<br />
Default: `1000`<br />

The maximum size of the cache.

### CACHE\_TTL

ENV: <b>CACHE\_TTL</b><br />
Type: `string`<br />
Default: `1h`<br />

The time-to-live for cache entries.

### CACHE\_CLEANUP\_INTERVAL

ENV: <b>CACHE\_CLEANUP\_INTERVAL</b><br />
Type: `string`<br />
Default: `10m`<br />

The cleanup interval for the cache.

### CACHE\_PERSIST\_TO\_DB

ENV: <b>CACHE\_PERSIST\_TO\_DB</b><br />
Type: `boolean`<br />
Default: `false`<br />

Persist the cache to the database.

### GATEWAY\_TIMEOUT

ENV: <b>GATEWAY\_TIMEOUT</b><br />
Type: `string`<br />
Default: `30s`<br />

The timeout for the gateway.

### GATEWAY\_MAX\_REQUEST\_SIZE

ENV: <b>GATEWAY\_MAX\_REQUEST\_SIZE</b><br />
Type: `integer`<br />
Default: `10485760`<br />

The maximum request size for the gateway.

### GATEWAY\_MAX\_RESPONSE\_SIZE

ENV: <b>GATEWAY\_MAX\_RESPONSE\_SIZE</b><br />
Type: `integer`<br />
Default: `52428800`<br />

The maximum response size for the gateway.

### GATEWAY\_DEFAULT\_RATE\_LIMIT

ENV: <b>GATEWAY\_DEFAULT\_RATE\_LIMIT</b><br />
Type: `integer`<br />
Default: `100`<br />

The default rate limit for the gateway.

### GATEWAY\_ENABLE\_FILTERS

ENV: <b>GATEWAY\_ENABLE\_FILTERS</b><br />
Type: `boolean`<br />
Default: `true`<br />

Enable filters in the gateway.

### GATEWAY\_ENABLE\_ANALYTICS

ENV: <b>GATEWAY\_ENABLE\_ANALYTICS</b><br />
Type: `boolean`<br />
Default: `true`<br />

Enable analytics in the gateway.

### ANALYTICS\_ENABLED

ENV: <b>ANALYTICS\_ENABLED</b><br />
Type: `boolean`<br />
Default: `true`<br />

Enable analytics.

### ANALYTICS\_BUFFER\_SIZE

ENV: <b>ANALYTICS\_BUFFER\_SIZE</b><br />
Type: `integer`<br />
Default: `1000`<br />

The buffer size for analytics.

### ANALYTICS\_FLUSH\_INTERVAL

ENV: <b>ANALYTICS\_FLUSH\_INTERVAL</b><br />
Type: `string`<br />
Default: `10s`<br />

The flush interval for analytics.

### ANALYTICS\_RETENTION\_DAYS

ENV: <b>ANALYTICS\_RETENTION\_DAYS</b><br />
Type: `integer`<br />
Default: `90`<br />

The retention period for analytics in days.

### ANALYTICS\_REALTIME

ENV: <b>ANALYTICS\_REALTIME</b><br />
Type: `boolean`<br />
Default: `false`<br />

Enable real-time analytics.

### JWT\_SECRET

ENV: <b>JWT\_SECRET</b><br />
Type: `string`<br />
Default: `change-me-in-production`<br />

The secret key for JWTs.

### ENCRYPTION\_KEY

ENV: <b>ENCRYPTION\_KEY</b><br />
Type: `string`<br />
Default: `change-me-in-production`<br />

The encryption key.

### BCRYPT\_COST

ENV: <b>BCRYPT\_COST</b><br />
Type: `integer`<br />
Default: `10`<br />

The cost factor for bcrypt.

### TOKEN\_LENGTH

ENV: <b>TOKEN\_LENGTH</b><br />
Type: `integer`<br />
Default: `32`<br />

The length of generated tokens.

### SESSION\_TIMEOUT

ENV: <b>SESSION\_TIMEOUT</b><br />
Type: `string`<br />
Default: `24h`<br />

The timeout for sessions.

### ENABLE\_RATE\_LIMITING

ENV: <b>ENABLE\_RATE\_LIMITING</b><br />
Type: `boolean`<br />
Default: `true`<br />

Enable rate limiting.

### ENABLE\_IP\_WHITELIST

ENV: <b>ENABLE\_IP\_WHITELIST</b><br />
Type: `boolean`<br />
Default: `false`<br />

Enable IP whitelisting.

### LOG\_LEVEL

ENV: <b>LOG\_LEVEL</b><br />
Type: `string`<br />
Default: `info`<br />

The log level.

### LOG\_FORMAT

ENV: <b>LOG\_FORMAT</b><br />
Type: `string`<br />
Default: `text`<br />

The log format (`json` or `text`).

### ENABLE\_METRICS

ENV: <b>ENABLE\_METRICS</b><br />
Type: `boolean`<br />
Default: `true`<br />

Enable metrics.

### METRICS\_PATH

ENV: <b>METRICS\_PATH</b><br />
Type: `string`<br />
Default: `/metrics`<br />

The path for metrics.

### ENABLE\_TRACING

ENV: <b>ENABLE\_TRACING</b><br />
Type: `boolean`<br />
Default: `false`<br />

Enable tracing.

### TRACING\_ENDPOINT

ENV: <b>TRACING\_ENDPOINT</b><br />
Type: `string`<br />

The endpoint for tracing.

### ENABLE\_PROFILING

ENV: <b>ENABLE\_PROFILING</b><br />
Type: `boolean`<br />
Default: `false`<br />

Enable profiling.

### GATEWAY\_MODE

ENV: <b>GATEWAY\_MODE</b><br />
Type: `string`<br />
Default: `standalone`<br />

The gateway mode (`standalone` or `edge`).

### CONTROL\_ENDPOINT

ENV: <b>CONTROL\_ENDPOINT</b><br />
Type: `string`<br />

The gRPC endpoint of the control plane.

### EDGE\_ID

ENV: <b>EDGE\_ID</b><br />
Type: `string`<br />

A unique ID for the edge gateway.

### EDGE\_NAMESPACE

ENV: <b>EDGE\_NAMESPACE</b><br />
Type: `string`<br />

The namespace for the edge gateway.

### EDGE\_RECONNECT\_INTERVAL

ENV: <b>EDGE\_RECONNECT\_INTERVAL</b><br />
Type: `string`<br />
Default: `5s`<br />

The interval to wait before reconnecting to the control plane.

### EDGE\_HEARTBEAT\_INTERVAL

ENV: <b>EDGE\_HEARTBEAT\_INTERVAL</b><br />
Type: `string`<br />
Default: `30s`<br />

The interval for sending heartbeats to the control plane.

### EDGE\_SYNC\_TIMEOUT

ENV: <b>EDGE\_SYNC\_TIMEOUT</b><br />
Type: `string`<br />
Default: `10s`<br />

The timeout for syncing configuration from the control plane.

### EDGE\_AUTH\_TOKEN

ENV: <b>EDGE\_AUTH\_TOKEN</b><br />
Type: `string`<br />

The authentication token for connecting to the control plane.

### EDGE\_TLS\_ENABLED

ENV: <b>EDGE\_TLS\_ENABLED</b><br />
Type: `boolean`<br />
Default: `true`<br />

Enable TLS for the connection to the control plane.

### EDGE\_TLS\_CERT\_PATH

ENV: <b>EDGE\_TLS\_CERT\_PATH</b><br />
Type: `string`<br />

The path to the client TLS certificate file.

### EDGE\_TLS\_KEY\_PATH

ENV: <b>EDGE\_TLS\_KEY\_PATH</b><br />
Type: `string`<br />

The path to the client TLS key file.

### EDGE\_TLS\_CA\_PATH

ENV: <b>EDGE\_TLS\_CA\_PATH</b><br />
Type: `string`<br />

The path to the CA certificate file for verifying the control plane's certificate.

### EDGE\_SKIP\_TLS\_VERIFY

ENV: <b>EDGE\_SKIP\_TLS\_VERIFY</b><br />
Type: `boolean`<br />
Default: `false`<br />

Skip TLS certificate verification.

### EDGE\_ALLOW\_INSECURE

ENV: <b>EDGE\_ALLOW\_INSECURE</b><br />
Type: `boolean`<br />
Default: `false`<br />

Allow insecure connections to the control plane.
