|
5 | 5 | - content/nginx-one/getting-started.md |
6 | 6 | --- |
7 | 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): |
| 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 | | -# 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 |
13 | 12 | # |
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 | + } |
20 | 26 |
|
21 | | -This configuration: |
| 27 | + # Serve the dashboard page at /dashboard.html |
| 28 | + location = /dashboard.html { |
| 29 | + root /usr/share/nginx/html; |
| 30 | + } |
22 | 31 |
|
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 | +``` |
26 | 38 |
|
27 | 39 | For more details, see the [NGINX Plus API module documentation](https://nginx.org/en/docs/http/ngx_http_api_module.html). |
28 | 40 |
|
|
0 commit comments