# nginx: [emerg] 1024 zones are not enough in "limit_conn_zone"

- **ID:** `nginx/limit-conn-zone-too-small`
- **Domain:** nginx
- **Category:** resource_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

The limit_conn_zone directive allocates a fixed number of slots (default 1024) for tracking connections per key, which is exhausted under high concurrency.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| nginx/1.18.0 | active | — | — |
| nginx/1.20.0 | active | — | — |
| nginx/1.24.0 | active | — | — |
| nginx/1.26.0 | active | — | — |

## Workarounds

1. **Increase the zone size in the limit_conn_zone directive: `limit_conn_zone $binary_remote_addr zone=addr:10m;` (default is 1m, which holds ~1024 zones)** (90% success)
   ```
   Increase the zone size in the limit_conn_zone directive: `limit_conn_zone $binary_remote_addr zone=addr:10m;` (default is 1m, which holds ~1024 zones)
   ```
2. **If using multiple keys, create separate zones for each key to distribute the load: `limit_conn_zone $server_name zone=server:5m; limit_conn_zone $binary_remote_addr zone=addr:5m;`** (85% success)
   ```
   If using multiple keys, create separate zones for each key to distribute the load: `limit_conn_zone $server_name zone=server:5m; limit_conn_zone $binary_remote_addr zone=addr:5m;`
   ```
3. **Monitor zone usage with the status module and adjust dynamically: add `stub_status;` to a location and check active connections to estimate required zone size.** (75% success)
   ```
   Monitor zone usage with the status module and adjust dynamically: add `stub_status;` to a location and check active connections to estimate required zone size.
   ```

## Dead Ends

- **** — limit_conn controls the maximum number of connections per key, not the number of zones/slots available for tracking. (80% fail)
- **** — This eliminates the error but also removes the intended connection limiting functionality, potentially leading to resource exhaustion. (30% fail)
- **** — Large zones consume significant memory; if the system runs out of memory, nginx may crash or fail to start. (50% fail)
