Skip to content

Commit ea520d6

Browse files
committed
updated nginx plus api server block to enable the dashboard
1 parent 9df3955 commit ea520d6

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,36 @@ files:
55
- content/nginx-one/getting-started.md
66
---
77
<!-- 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):
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):
99

1010
```nginx
11-
# Enable the /api/ location with appropriate access control
12-
# to use the NGINX Plus API.
11+
# Server block for enabling the NGINX Plus API and dashboard
1312
#
14-
location /api/ {
15-
api write=on;
16-
allow 127.0.0.1;
17-
deny all;
18-
}
19-
```
13+
# This block requires NGINX Plus. It turns on the API in write mode
14+
# and serves the built-in dashboard for monitoring.
15+
# Change the listen port if 9000 conflicts; 8080 is the conventional API port.
16+
# For production, secure the API with TLS and limit access by IP or auth.
17+
server {
18+
# Listen for API and dashboard traffic
19+
listen 9000 default_server;
20+
server_name localhost;
21+
22+
# Handle API calls under /api/ in read-write mode
23+
location /api/ {
24+
api write=on;
25+
}
2026
21-
This configuration:
27+
# Serve the dashboard page at /dashboard.html
28+
location = /dashboard.html {
29+
root /usr/share/nginx/html;
30+
}
2231
23-
- Enables the NGINX Plus API.
24-
- Allows requests only from `127.0.0.1` (localhost).
25-
- Blocks all other requests for security.
32+
# Redirect any request to the root path “/” to the dashboard
33+
location / {
34+
return 301 /dashboard.html;
35+
}
36+
}
37+
```
2638

2739
For more details, see the [NGINX Plus API module documentation](https://nginx.org/en/docs/http/ngx_http_api_module.html).
2840

0 commit comments

Comments
 (0)