Skip to content

Commit 1079afc

Browse files
Updated the config snippet for enabling the NGINX Plus API and dashboard (#739)
* updated the nginx config snippet for enabling the NGINX Plus API and dashboard * edits * Update content/includes/use-cases/monitoring/enable-nginx-plus-api.md Co-authored-by: Alan Dooley <[email protected]> * edits per tech review --------- Co-authored-by: Alan Dooley <[email protected]>
1 parent 8b3c338 commit 1079afc

File tree

2 files changed

+45
-54
lines changed

2 files changed

+45
-54
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
docs:
3+
files:
4+
- content/nginx-one/workshops/lab5/upgrade-nginx-plus-to-latest-version.md
5+
- content/includes/use-cases/monitoring/enable-nginx-plus-api.md
6+
---
7+
8+
```nginx
9+
# This block enables the NGINX Plus API and dashboard
10+
# For configuration and security recommendations, see:
11+
# https://docs.nginx.com/nginx/admin-guide/monitoring/live-activity-monitoring/#configuring-the-api
12+
server {
13+
# Change the listen port if 9000 conflicts
14+
# (8080 is the conventional API port)
15+
listen 9000;
16+
17+
location /api/ {
18+
# To restrict write methods (POST, PATCH, DELETE), uncomment:
19+
# limit_except GET {
20+
# auth_basic "NGINX Plus API";
21+
# auth_basic_user_file /path/to/passwd/file;
22+
# }
23+
24+
# Enable API in write mode
25+
api write=on;
26+
27+
# To restrict access by network, uncomment and set your network:
28+
# allow 192.0.2.0/24 # replace with your network
29+
# deny all;
30+
}
31+
32+
# Serve the built-in dashboard at /dashboard.html
33+
location = /dashboard.html {
34+
root /usr/share/nginx/html;
35+
}
36+
}
37+
```

content/includes/use-cases/monitoring/enable-nginx-plus-api.md

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,15 @@ files:
44
- content/nim/monitoring/overview-metrics.md
55
- content/nginx-one/getting-started.md
66
---
7-
<!-- include in content/nginx-one/getting-started.md disabled, hopefully temporarily -->
8-
To collect comprehensive metrics for NGINX Plus -- including bytes streamed, information about upstream systems and caches, and counts of all HTTP status codes -- add the following to your NGINX Plus configuration file (for example, `/etc/nginx/nginx.conf` or an included file):
97

10-
```nginx
11-
# This block:
12-
# - Enables the read-write NGINX Plus API under /api/
13-
# - Serves the built-in dashboard at /dashboard.html
14-
# - Restricts write methods (POST, PATCH, DELETE) to authenticated users
15-
# and a specified IP range
16-
# Change the listen port if 9000 conflicts; 8080 is the conventional API port.
17-
server {
18-
# Listen on port 9000 for API and dashboard traffic
19-
listen 9000 default_server;
8+
To collect comprehensive metrics for NGINX Plus, including bytes streamed, information about upstream systems and caches, and counts of all HTTP status codes, add the following to your NGINX Plus configuration file, for example `/etc/nginx/nginx.conf` or an included file:
209

21-
# Handle API calls under /api/
22-
location /api/ {
23-
# Enable write operations (POST, PATCH, DELETE)
24-
api write=on;
10+
{{< include "config-snippets/enable-nplus-api-dashboard.md" >}}
2511

26-
# Allow GET requests from any IP
27-
allow 0.0.0.0/0;
28-
# Deny all other requests by default
29-
deny all;
12+
{{< call-out "note" "Security tip" >}}
13+
- By default, all clients can call the API.
14+
- To limit who can access the API, uncomment the `allow` and `deny` lines under `api write=on` and replace the example CIDR with your trusted network.
15+
- To restrict write methods (`POST`, `PATCH`, `DELETE`), uncomment and configure the `limit_except GET` block and set up [HTTP basic authentication](https://nginx.org/en/docs/http/ngx_http_auth_basic_module.html).
16+
{{</ call-out >}}
3017

31-
# For methods other than GET, require auth and restrict to a network
32-
limit_except GET {
33-
# Prompt for credentials with this realm
34-
auth_basic "NGINX Plus API";
35-
# Path to the file with usernames and passwords
36-
auth_basic_user_file /path/to/passwd/file;
37-
38-
# Allow only this IP range (replace with your own)
39-
allow 192.0.2.0/24;
40-
# Deny all other IPs
41-
deny all;
42-
}
43-
}
44-
45-
# Serve the dashboard page at /dashboard.html
46-
location = /dashboard.html {
47-
# Files are located under this directory
48-
root /usr/share/nginx/html;
49-
}
50-
51-
# Redirect any request for / to the dashboard
52-
location / {
53-
return 301 /dashboard.html;
54-
}
55-
}
56-
```
57-
58-
For more details, see the [NGINX Plus API module documentation](https://nginx.org/en/docs/http/ngx_http_api_module.html) and [Configuring the NGINX Plus API]({{< ref "nginx/admin-guide/monitoring/live-activity-monitoring.md#configuring-the-api" >}}).
59-
60-
After saving the changes, reload NGINX:
61-
62-
```shell
63-
nginx -s reload
64-
```
18+
For more details, see the [NGINX Plus API module](https://nginx.org/en/docs/http/ngx_http_api_module.html) documentation and [Configuring the NGINX Plus API]({{< ref "/nginx/admin-guide/monitoring/live-activity-monitoring.md#configuring-the-api" >}}).

0 commit comments

Comments
 (0)