DNAbyD3Docs
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-http library.
  • An API key.

Install

The script, sample config, and full guide are in the adapters repo: github.com/d3-inc/d3-edge-adapters/nginx.

  1. Save the script.
  2. From the sample config, add the env lines and the http {} settings.
  3. Add one access_by_lua_file line per protected location.
  4. Set the environment variables where nginx starts, with your API key in DNA_API_KEY.
  5. Reload nginx.
  6. Verify the install.

Configuration

The repo README documents every variable.

  • DNA_API_KEY unset: 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.

HeaderValue
X-D3-TierWho is asking, as a tier code
X-D3-IdentityThe 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.

On this page