Middleware
Nginx
A Lua script for OpenResty that asks DNA for a decision and enforces it.
On nginx, DNA is a small Lua script that checks each request before your site
sees it, and lets it through or returns a 403.
Requirements
- nginx with Lua support: OpenResty, or a build with
ngx_http_lua_module(Kong and APISIX ship it). - The
lua-resty-httplibrary. - An API key.
Install
The script, sample config, and full guide are in the adapters repo: github.com/d3-inc/d3-edge-adapters/nginx.
- Save the script.
- From the sample config, add the
envlines and thehttp {}settings. - Add one
access_by_lua_fileline per protected location. - Set the environment variables where nginx starts, with your API key in
DNA_API_KEY. - Reload nginx.
- Verify the install.
Configuration
The repo README documents every variable.
DNA_API_KEYunset: the script is a silent passthrough.- If no decision arrives within the cutoff, your site serves the request as usual.
Response shape
Every response has an x-d3-edge header: disabled, pass, block,
fail-open, or fail-closed.
A blocked request gets a 403 with a JSON body:
{ "blocked": true, "ruleId": "…", "tier": "…", "identity": "…" }Upstream headers
On pass, the script sets these request headers for your upstream. Other DNA installs don't.
| Header | Value |
|---|---|
X-D3-Tier | Who is asking, as a tier code |
X-D3-Identity | The agent's identity, at that tier |
- The script sets them on every pass, so a client can't spoof them past it.
- Your application can act on them, for example to serve a lighter page to a crawler or skip analytics for bots.