|
4 | 4 | - content/nim/monitoring/overview-metrics.md
|
5 | 5 | - content/nginx-one/getting-started.md
|
6 | 6 | ---
|
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): |
9 | 7 |
|
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: |
20 | 9 |
|
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" >}} |
25 | 11 |
|
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 >}} |
30 | 17 |
|
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