nginx
Put DNA in front of every request nginx serves, with plain nginx or OpenResty.
Add DNA to the locations that serve your site and nginx asks it about every
request before your site sees it. A request DNA keeps out gets a 403;
everything else reaches your site as usual.
Choose an install
| Your nginx | Install | You add |
|---|---|---|
| Any nginx from your distro's packages | auth_request | A config block, no modules |
| OpenResty, or a gateway on it (Kong, APISIX) | Lua script | One script and one line |
Price routes with Payments? Use the Lua script: the
auth_request install serves a priced route as an ordinary page.
Both need an API key.
auth_request
Confirm your nginx has the module (every distro package does):
nginx -V 2>&1 | grep auth_request-
Open the config in the adapters repo: nginx-auth-request/d3-edge.conf.
-
Merge it into your config: the
upstreamblock once, and thelocation = /_d3_edgeblock into eachserveryou want covered. -
Add the check to every
locationthat serves your site, not onlylocation /:/api/, a~ \.php$block and any other. The file shows the pattern onlocation /:auth_request /_d3_edge;anderror_page 500 = @<fallback>;inside the location;- a named
@<fallback>location withauth_request off;and the same handler as the location it mirrors (itsproxy_pass,fastcgi_passorroot), so your site keeps serving if DNA can't be reached.
A location without these lines serves its requests without DNA.
-
Replace
d3_k_REPLACE_MEwith your key. nginx config can't read environment variables, so restrict the file as you would any config with a credential. -
Test and reload:
nginx -t && nginx -s reload -
Verify the install on a page from each location.
A request DNA keeps out gets nginx's own 403 page.
Lua script
Needs nginx with Lua: OpenResty, or a build with
ngx_http_lua_module, plus the lua-resty-http library.
- Save the script from d3-dna-adapters/openresty.
- From the sample config, add the
envlines and thehttp {}settings. - Add
access_by_lua_fileonce in yourserverblock, so every location inherits it. - Set
DNA_API_KEYwhere nginx starts. - Reload nginx and verify the install.
With DNA_API_KEY unset, the script lets every request through. The repo
README documents every variable.
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.
| 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.