Skip to content

Commit 9cc8509

Browse files
nginx-nickcmjang
andauthored
docs: added guide for working with NGINX Configs (#1086)
* docs: added guide for working with NGINX Configs Co-authored-by: Mike Jang <[email protected]>
1 parent 248094d commit 9cc8509

File tree

1 file changed

+161
-0
lines changed

1 file changed

+161
-0
lines changed
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
---
2+
description: ''
3+
nd-docs: DOCS-000
4+
title: Manage NGINX configurations with API requests
5+
toc: true
6+
weight: 100
7+
type:
8+
- how-to
9+
---
10+
11+
In this guide, we'll show you how to use API requests to update NGINX Configurations for Instances, Config Sync Groups, or Staged Configs in the F5 NGINX One Console.
12+
13+
## Before you begin
14+
15+
Before you begin, make sure you can properly authenticate your API requests with either an API Token or API Certificate, following the instructions in the [Authentication]({{<ref "/nginx-one/api/authentication.md" >}}) guide. To ensure you have registered or created your NGINX Instance, Config Sync Group, or Staged Config in the F5 NGINX One Console, follow the instructions in the [Manage your NGINX instances]({{<ref "/nginx-one/nginx-configs/" >}}) guide.
16+
17+
{{< call-out "note" >}}
18+
The workflows for managing NGINX Configs for Instances, Config Sync Groups, and Staged Configs in the F5 NGINX One Console are quite similar. This guide focuses on the steps for updating NGINX Configs for Instances. If you're working with Config Sync Groups, you'll follow a similar process but will need to update the API endpoints appropriately.
19+
{{< /call-out>}}
20+
21+
## Get the current NGINX configuration
22+
23+
You can retrieve the current NGINX configuration for an Instance, Config Sync Group, or Staged Config using a `GET` request. This is useful for making updates based on the existing configuration.
24+
25+
Use the following `curl` command to retrieve the current NGINX configuration for a specific Instance. Replace `<tenant>`, `<namespace>`, `<instance-object-id>`, and `<token-value>` with your actual values.
26+
27+
```shell
28+
curl -X GET "https://<tenant>.console.ves.volterra.io/api/nginx/one/namespaces/<namespace>/instances/<instance-object-id>/config" \
29+
-H "Authorization: APIToken <token-value>" -o current_config.json
30+
```
31+
32+
- `<tenant>`: Your tenant name for organization plans.
33+
- `<namespace>`: The namespace your Instance belongs to.
34+
- `<instance-object-id>`: The object_id of the NGINX Instance you want to retrieve the NGINX configuration for.
35+
- `<token-value>`: Your API Token.
36+
37+
{{< call-out "note" >}}
38+
To update the NGINX configuration for a Config Sync Group or Staged Config, replace `instances` with `config-sync-groups` or `staged-configs` and use the object_id of the Config Sync Group or Staged Config in the URL.
39+
{{< /call-out>}}
40+
41+
The response will include the current NGINX configuration in JSON format. This response is saved to a file (with a name like `current_config.json`) for editing.
42+
43+
You can modify the NGINX configuration using either `PUT` or `PATCH` requests. The `PUT` method replaces the entire NGINX configuration, while the `PATCH` method allows you to update specific fields without affecting the rest of the configuration.
44+
45+
## How to base64 encode a file for JSON request
46+
47+
When updating the NGINX Config, file `contents` must be base64 encoded. You can use the following command to base64 encode a file:
48+
49+
```shell
50+
base64 -w 0 -i <path-to-your-file>
51+
```
52+
53+
This command reads the file at `<path-to-your-file>` and outputs its base64 encoded content in a single line (due to the `-w 0` option). You can then copy this encoded string and include it in your JSON request body. On some systems the `-w` option may not be available, in which case you can use:
54+
55+
```shell
56+
base64 -i <path-to-your-file> | tr -d '\n'
57+
```
58+
59+
## Update the NGINX configuration for an Instance using `PUT`
60+
61+
When using the `PUT` method, ensure that your request body includes all necessary contents, as it will overwrite the existing configuration.
62+
The following example demonstrates how to update the NGINX configuration for a specific Instance using `PUT`. Replace `<tenant>`, `<namespace>`, `<instance-object-id>`, and `<token-value>` with your actual values. The request body should contain the complete NGINX configuration in JSON format.
63+
64+
```shell
65+
curl -X PUT "https://<tenant>.console.ves.volterra.io/api/nginx/one/namespaces/<namespace>/instances/<instance-object-id>/config" \
66+
-H "Authorization : APIToken <token-value>" \
67+
-H "Content-Type: application/json" \
68+
-d @updated_config.json
69+
```
70+
71+
- `<tenant>`: Your tenant name for organization plans.
72+
- `<namespace>`: The namespace your Instance belongs to.
73+
- `<instance-object-id>`: The object_id of the NGINX Instance you want to update the NGINX configuration for.
74+
- `<token-value>`: Your API Token.
75+
76+
## Update the NGINX configuration for an Instance using `PATCH`
77+
78+
When using the `PATCH` method, you only need to include the files you want to update in your request body.
79+
The following example demonstrates how to update the NGINX configuration for a specific Instance using `PATCH`. Replace `<tenant>`, `<namespace>`, `<instance-object-id>`, and `<token-value>` with your actual values. The request body should contain only the fields you want to update in JSON format.
80+
```shell
81+
curl -X PATCH "https://<tenant>.console.ves.volterra.io/api/nginx/one/namespaces/<namespace>/instances/<instance-object-id>/config" \
82+
-H "Authorization : APIToken <token-value>" \
83+
-H "Content-Type: application/json" \
84+
-d @partial_update_config.json
85+
```
86+
87+
- `<tenant>`: Your tenant name for organization plans.
88+
- `<namespace>`: The namespace your Instance belongs to.
89+
- `<instance-object-id>`: The object_id of the NGINX Instance you want to update the NGINX configuration for.
90+
- `<token-value>`: Your API Token.
91+
92+
With `PATCH`, you can update specific parts of the NGINX Instance configuration without needing to resend the entire configuration. The following file `contents` disposition is observed:
93+
- Leave out file `contents` to remove the file from the NGINX Config.
94+
- Include file `contents` to add or update the file in the NGINX Config. File `contents` must be base64 encoded. File `contents` can be an empty string to create an empty file.
95+
- `config_version` should be included to ensure you're updating the correct version of the configuration. You can get the current `config_version` from the response of the `GET` request.
96+
97+
For example, to update only the `/etc/nginx/nginx.conf` file in the NGINX Config, your `partial_update_config.json` might look like this:
98+
```json
99+
{
100+
"conf_path": "/etc/nginx/nginx.conf",
101+
"config_version": "<config_version from GET response>",
102+
"configs": [
103+
{
104+
"name": "/etc/nginx",
105+
"files": [
106+
{
107+
"name": "nginx.conf",
108+
"contents": "<base64-encoded-content-here>"
109+
}
110+
]
111+
}
112+
]
113+
}
114+
```
115+
116+
To remove a file, omit the `contents` field for that file in your `PATCH` request body, your `partial_update_config.json` might look like this to remove `/etc/nginx/conf.d/default.conf` from the NGINX Instance configuration:
117+
```json
118+
{
119+
"conf_path": "/etc/nginx/nginx.conf",
120+
"config_version": "<config_version from GET response>",
121+
"configs": [
122+
{
123+
"name": "/etc/nginx/conf.d",
124+
"files": [
125+
{
126+
"name": "default.conf"
127+
}
128+
]
129+
}
130+
]
131+
}
132+
```
133+
134+
## Set up multiple updates with `PATCH`
135+
136+
You can make multiple updates can be made in a single `PATCH` request. For example, to update `/etc/nginx/nginx.conf` and remove `/etc/nginx/conf.d/default.conf`, your `partial_update_config.json` might look like this:
137+
```json
138+
{
139+
"conf_path": "/etc/nginx/nginx.conf",
140+
"config_version": "<config_version from GET response>",
141+
"configs": [
142+
{
143+
"name": "/etc/nginx/conf.d",
144+
"files": [
145+
{
146+
"name": "default.conf"
147+
}
148+
]
149+
},
150+
{
151+
"name": "/etc/nginx",
152+
"files": [
153+
{
154+
"name": "nginx.conf",
155+
"contents": "<base64-encoded-content-here>"
156+
}
157+
]
158+
}
159+
]
160+
}
161+
```

0 commit comments

Comments
 (0)