-
Notifications
You must be signed in to change notification settings - Fork 123
Update N1C getting started guide with instructions on how to enable metrics collection for a NGINX Plus API with SSL enabled #1496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,53 @@ | ||||||
| --- | ||||||
| nd-product: MSC | ||||||
| nd-files: | ||||||
| - content/nginx-one-console/getting-started.md | ||||||
| - content/nginx-one-console/nginx-configs/metrics/enable-metrics.md | ||||||
| - content/nim/monitoring/overview-metrics.md | ||||||
| - content/nim/nginx-instances/add-instance.md | ||||||
| --- | ||||||
|
|
||||||
| To collect basic metrics about server activity for NGINX Open Source: | ||||||
|
|
||||||
| 1. **Enable the stub status API** | ||||||
|
|
||||||
| Add the following to your NGINX configuration file: | ||||||
|
|
||||||
| ```nginx | ||||||
| server { | ||||||
| listen 127.0.0.1:8080; | ||||||
| location /api { | ||||||
| stub_status; | ||||||
| allow 127.0.0.1; | ||||||
| deny all; | ||||||
| } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| {{<call-out type="important" title="Important">}} | ||||||
| Make sure that the `server` and `location` blocks are in the same single configuration file, and not split across multiple files using `include` directives. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| {{</call-out>}} | ||||||
|
|
||||||
| This configuration: | ||||||
|
|
||||||
| - Enables the stub status API endpoint | ||||||
| - Allows requests only from `127.0.0.1` (localhost). | ||||||
| - Blocks all other requests for security. | ||||||
|
|
||||||
| For more details, see the [NGINX Stub Status module documentation](https://nginx.org/en/docs/http/ngx_http_stub_status_module.html). | ||||||
|
|
||||||
| 2. **Configure access logging** | ||||||
|
|
||||||
| Enable access logging in your NGINX configuration to collect detailed traffic metrics. Ensure that the following log format is used: | ||||||
|
|
||||||
| ```nginx | ||||||
| log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | ||||||
| '$status $body_bytes_sent "$http_referer" ' | ||||||
| '"$http_user_agent" "$http_x_forwarded_for" ' | ||||||
| '"$bytes_sent" "$request_length" "$request_time" ' | ||||||
| '"$gzip_ratio" $server_protocol '; | ||||||
| access_log /var/log/nginx/access.log main; | ||||||
| ``` | ||||||
|
|
||||||
| This log format captures key metrics including request timing, response sizes and client information. | ||||||
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,58 @@ | ||||||||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||||||||
| nd-product: MSC | ||||||||||||||||||||||||||||||||||||
| nd-files: | ||||||||||||||||||||||||||||||||||||
| - content/nginx-one-console/getting-started.md | ||||||||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| If SSL is enabled on the NGINX Plus API with self-signed certificates like this example: | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ```nginx | ||||||||||||||||||||||||||||||||||||
| # This block enables the NGINX Plus API and dashboard with SSL | ||||||||||||||||||||||||||||||||||||
| # For configuration and security recommendations, see: | ||||||||||||||||||||||||||||||||||||
| # https://docs.nginx.com/nginx/admin-guide/monitoring/live-activity-monitoring/#configuring-the-api | ||||||||||||||||||||||||||||||||||||
| server { | ||||||||||||||||||||||||||||||||||||
| # Change the listen port if 9000 conflicts | ||||||||||||||||||||||||||||||||||||
| # (8080 is the conventional API port) | ||||||||||||||||||||||||||||||||||||
| listen 9000 ssl; | ||||||||||||||||||||||||||||||||||||
| ssl_certificate /etc/nginx/certs/nginx-selfsigned.crt; | ||||||||||||||||||||||||||||||||||||
| ssl_certificate_key /etc/nginx/certs/nginx-selfsigned.key; | ||||||||||||||||||||||||||||||||||||
| location /api/ { | ||||||||||||||||||||||||||||||||||||
| # To restrict write methods (POST, PATCH, DELETE), uncomment: | ||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think we can take out the commented section for http basic auth. Keep the example clear for ssl only. |
||||||||||||||||||||||||||||||||||||
| # limit_except GET { | ||||||||||||||||||||||||||||||||||||
| # auth_basic "NGINX Plus API"; | ||||||||||||||||||||||||||||||||||||
| # auth_basic_user_file /path/to/passwd/file; | ||||||||||||||||||||||||||||||||||||
| # } | ||||||||||||||||||||||||||||||||||||
| # Enable API in write mode | ||||||||||||||||||||||||||||||||||||
| api write=on; | ||||||||||||||||||||||||||||||||||||
| # To restrict access by network, uncomment the following lines and set your network: | ||||||||||||||||||||||||||||||||||||
| # allow 192.0.2.0/24; # replace with your network | ||||||||||||||||||||||||||||||||||||
| # allow 127.0.0.1/32; # allow local NGINX Agent to call the NGINX Plus API to retrieve metrics | ||||||||||||||||||||||||||||||||||||
| # deny all; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| # Serve the built-in dashboard at /dashboard.html | ||||||||||||||||||||||||||||||||||||
| location = /dashboard.html { | ||||||||||||||||||||||||||||||||||||
| root /usr/share/nginx/html; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| {{<call-out type="important" title="Important">}} | ||||||||||||||||||||||||||||||||||||
| Make sure that the `server` and `location` blocks are in the same single configuration file, and not split across multiple files using `include` directives. | ||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||
| {{</call-out>}} | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| NGINX Agent configuration needs to be update with the following to enable the NGINX Agent to be able to call the NGINX Plus API. | ||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||
| data_plane_config: | ||||||||||||||||||||||||||||||||||||
| nginx: | ||||||||||||||||||||||||||||||||||||
| api_tls: | ||||||||||||||||||||||||||||||||||||
| ca: "/etc/nginx/certs/nginx-selfsigned.crt" | ||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+47
to
+53
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
data_plane_config: |
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| Here is an example of how to generate self-signed certificates | ||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formatting
Suggested change
|
||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||
| openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/certs/nginx-selfsigned.key -out /etc/nginx/certs/nginx-selfsigned.crt -subj "/CN=localhost" -addext "subjectAltName=IP:127.0.0.1" | ||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formatting
Suggested change
|
||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.