Nginx Proxy Guard

Reference

API

Everything the admin panel does is also available through the REST API (/api/v1); the panel itself uses this API. Scripts and automation tools authenticate with an API token.

Address

Call the API at the same address as the admin panel. The admin panel container passes the /api path on to the API container.

https://<server address>:81/api/v1

The admin panel uses a self-signed certificate created at installation, so add -k to curl or configure it to trust that certificate. On the server itself you can also call the API port directly (http://127.0.0.1:9080/api/v1 in the standard installation).

API documentation (Swagger UI)

All endpoints with their request and response formats are in the Swagger UI. It opens without signing in.

https://<server address>:81/api/docs

The raw OpenAPI 3.0 specification is at /api/docs/swagger.yaml. The API Documentation button on the Account Settings → API Tokens tab opens the same page.

Creating an API token

Account Settings → API Tokens tab and the Create New API Token dialog
Account Settings → API Tokens tab and the Create New API Token dialog
  1. Click your username at the top right to open Account Settings and go to the API Tokens tab.
  2. Click Create Token.
  3. Enter a Token Name and choose one of the Permission Groups, or pick Individual Permissions one by one.
  4. Optionally list the addresses allowed to use the token, comma separated, in Allowed IPs (Optional), and choose Expires In.
  5. Copy the token (it starts with ng_). It will not be shown again.
Permission groupPermissions
Read Onlyproxy:read, certificate:read, waf:read, logs:read, settings:read, backup:read
Operatorproxy:read, proxy:write, certificate:read, certificate:write, waf:read, waf:write, logs:read, settings:read, backup:read, backup:create
Full Access* (everything)

What each individual permission reaches:

PermissionScope
proxy:read, proxy:writeProxy hosts, redirect hosts, access lists, auth providers
proxy:deleteDeleting proxy hosts and redirect hosts
certificate:read, certificate:write, certificate:deleteCertificates and DNS providers
waf:read, waf:writeThe whole WAF / Blocking menu (banned IPs, global security defaults and so on)
logs:readLogs
settings:readReading settings, the dashboard, DDNS, the audit log, API tokens and logs
settings:writeChanging settings, DDNS, API tokens and logs
backup:read, backup:create, backup:restoreListing, creating and restoring backups
user:readListing users

A token cannot have more permissions than the role of the person who creates it. Choosing a permission the role lacks refuses the creation, and if the role is narrowed later, what the token can do narrows with it. Revoke or Delete in the token list stops a token immediately. Token use is recorded in Logs → Admin Audit → API Token Usage.

Authentication

Send the token in the Authorization header of every request.

Authorization: Bearer ng_your_token_here

A sign-in session token from the admin panel works in the same header. Session tokens come from POST /api/v1/auth/login (followed by POST /api/v1/auth/verify-2fa with two-factor authentication) and are valid for 24 hours. For automation, API tokens are recommended, since their expiry and permissions can be set separately.

Example calls

The examples assume these two variables:

export NPG_URL="https://192.0.2.10:81"
export NPG_TOKEN="ng_your_token_here"

List proxy hosts (proxy:read)

curl -k -H "Authorization: Bearer $NPG_TOKEN" \
  "$NPG_URL/api/v1/proxy-hosts?page=1&per_page=50"

A page holds at most 100 hosts, and search matches domain names and the forward address.

Create a proxy host (proxy:write)

curl -k -X POST "$NPG_URL/api/v1/proxy-hosts" \
  -H "Authorization: Bearer $NPG_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "domain_names": ["app.example.com"],
    "forward_scheme": "http",
    "forward_host": "192.0.2.20",
    "forward_port": 8080
  }'

NPG writes the configuration, checks it with nginx -t and applies it. If the check fails, the host is not saved either. On success the answer is 201 with the new host. If the domain already exists, the answer is 409.

Ban and unban an IP address (waf:write)

# Ban for one hour (3600 seconds). A ban_time of 0 is permanent.
curl -k -X POST "$NPG_URL/api/v1/banned-ips" \
  -H "Authorization: Bearer $NPG_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"ip_address": "203.0.113.50", "reason": "manual ban from script", "ban_time": 3600}'

# Unban by address
curl -k -X DELETE -H "Authorization: Bearer $NPG_TOKEN" \
  "$NPG_URL/api/v1/banned-ips?ip=203.0.113.50"

With proxy_host_id in the body the ban applies to that host only; without it, it applies to every host.

Errors and rate limits

ResponseMeaning
401The token is missing, wrong, expired or revoked.
403The call came from an address not in Allowed IPs, or the token lacks a permission. The required field of the answer names the permission needed.
409A duplicate (such as a domain), or the configuration was saved but the running nginx refused to reload (code is nginx_reload_rejected).
429The rate limit was exceeded.

The API has a per-IP, per-minute rate limit: 600 requests for the general API and 100 for the sign-in endpoints by default, changed with API_RATE_LIMIT_PER_MINUTE and AUTH_RATE_LIMIT_PER_MINUTE (Environment variables). The response headers X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset show what is left.

Status endpoints

EndpointAuthenticationUse
GET /healthnoneCheck that the API answers
GET /api/v1/status, GET /api/v1/health/detailedany API token, whatever its permissionsStatus checks from monitoring tools
GET /metricsnonePrometheus metrics. Open only on the API port (127.0.0.1:9080).