|
8 | 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): |
9 | 9 |
|
10 | 10 | ```nginx |
11 | | -# Server block for enabling the NGINX Plus API and dashboard |
12 | | -# |
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. |
| 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 |
17 | 16 | server { |
18 | | - # Listen for API and dashboard traffic |
19 | | - listen 9000 default_server; |
20 | | - server_name localhost; |
| 17 | + listen 9000 default_server; |
| 18 | + # If port 9000 is in use, you can also use 8080: |
| 19 | + # listen 8080 default_server; |
| 20 | + server_name localhost; |
21 | 21 |
|
22 | 22 | # Handle API calls under /api/ in read-write mode |
23 | 23 | location /api/ { |
24 | 24 | api write=on; |
| 25 | +
|
| 26 | + # allow GET from anywhere |
| 27 | + allow 0.0.0.0/0; |
| 28 | + deny all; |
| 29 | +
|
| 30 | + # require auth and limit write methods to your network |
| 31 | + limit_except GET { |
| 32 | + auth_basic "NGINX Plus API"; |
| 33 | + auth_basic_user_file /etc/nginx/conf.d/api.htpasswd; |
| 34 | + allow 192.0.2.0/24 # example IP range; replace with yours |
| 35 | + deny all; |
| 36 | + } |
25 | 37 | } |
26 | 38 |
|
27 | 39 | # Serve the dashboard page at /dashboard.html |
28 | 40 | location = /dashboard.html { |
29 | 41 | root /usr/share/nginx/html; |
30 | 42 | } |
31 | 43 |
|
32 | | - # Redirect any request to the root path “/” to the dashboard |
| 44 | + # Redirect any request to “/” to the dashboard |
33 | 45 | location / { |
34 | 46 | return 301 /dashboard.html; |
35 | 47 | } |
36 | 48 | } |
37 | 49 | ``` |
38 | 50 |
|
39 | | -For more details, see the [NGINX Plus API module documentation](https://nginx.org/en/docs/http/ngx_http_api_module.html). |
| 51 | +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” >}}). |
40 | 52 |
|
41 | | -After saving the changes, reload NGINX to apply the new configuration: |
| 53 | +After saving the changes, reload NGINX: |
42 | 54 |
|
43 | 55 | ```shell |
44 | 56 | nginx -s reload |
|
0 commit comments