|
| 1 | +--- |
| 2 | +description: '' |
| 3 | +nd-docs: DOCS-1063 |
| 4 | +title: Working with NGINX Configs |
| 5 | +toc: true |
| 6 | +weight: 10 |
| 7 | +type: |
| 8 | +- how-to |
| 9 | +--- |
| 10 | + |
| 11 | +In this guide, we'll show you how to use API requests to update NGINX Configs for Instances or Config Sync Groups in the F5 NGINX One Console. |
| 12 | + |
| 13 | +## Getting ready |
| 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. Ensure you have registered or created your NGINX Instance or Config Sync Group 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 and Config Sync Groups 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 | +## Getting the current NGINX Config |
| 22 | + |
| 23 | +You can retrieve the current NGINX Config for an Instance or Config Sync Group 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 Config 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 | + - `<tenant>`: Your tenant name for organization plans. |
| 32 | + - `<namespace>`: The namespace your Instance belongs to. |
| 33 | + - `<instance-object-id>`: The object_id of the NGINX Instance you want to retrieve the NGINX Config for. |
| 34 | + - `<token-value>`: Your API Token. |
| 35 | + |
| 36 | +{{< call-out "note" >}} |
| 37 | +To update the NGINX Config for a Config Sync Group, replace `instances` with `config-sync-groups` and use the object_id of the Config Sync Group in the URL. |
| 38 | +{{< /call-out>}} |
| 39 | + |
| 40 | + The response will include the current NGINX Config in JSON format. This response is saved to a file (e.g., `current_config.json`) for editing. |
| 41 | + |
| 42 | +## Updating the NGINX Config |
| 43 | + |
| 44 | +You can modify the NGINX Config using either `PUT` or `PATCH` requests. The `PUT` method replaces the entire NGINX Config, while the `PATCH` method allows you to update specific fields without affecting the rest of the configuration. |
| 45 | + |
| 46 | +1. **Update the NGINX Config for an Instance using `PUT`**: |
| 47 | + |
| 48 | + When using the `PUT` method, ensure that your request body includes all necessary contents, as it will overwrite the existing configuration. |
| 49 | + The following example demonstrates how to update the NGINX Config 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 Config in JSON format. |
| 50 | + ```shell |
| 51 | + curl -X PUT "https://<tenant>.console.ves.volterra.io/api/nginx/one/namespaces/<namespace>/instances/<instance-object-id>/config" \ |
| 52 | + -H "Authorization : APIToken <token-value>" \ |
| 53 | + -H "Content-Type: application/json" \ |
| 54 | + -d @updated_config.json |
| 55 | + ``` |
| 56 | + - `<tenant>`: Your tenant name for organization plans. |
| 57 | + - `<namespace>`: The namespace your Instance belongs to. |
| 58 | + - `<instance-object-id>`: The object_id of the NGINX Instance you want to update the NGINX Config for. |
| 59 | + - `<token-value>`: Your API Token. |
| 60 | + |
| 61 | +2. **Update the NGINX Config for an Instance using `PATCH`**: |
| 62 | + |
| 63 | + When using the `PATCH` method, you only need to include the files you want to update in your request body. |
| 64 | + The following example demonstrates how to update the NGINX Config 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. |
| 65 | + ```shell |
| 66 | + curl -X PATCH "https://<tenant>.console.ves.volterra.io/api/nginx/one/namespaces/<namespace>/instances/<instance-object-id>/config" \ |
| 67 | + -H "Authorization : APIToken <token-value>" \ |
| 68 | + -H "Content-Type: application/json" \ |
| 69 | + -d @partial_update_config.json |
| 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 Config for. |
| 74 | + - `<token-value>`: Your API Token. |
| 75 | + |
| 76 | + With `PATCH`, you can update specific parts of the NGINX Config without needing to resend the entire configuration. The following file `contents` disposition is observed: |
| 77 | + - Leave out file `contents` to remove the file from the NGINX Config. |
| 78 | + - 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. |
| 79 | + - `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. |
| 80 | + For example, to update only the `nginx.conf` file in the NGINX Config, your `partial_update_config.json` might look like this: |
| 81 | + ```json |
| 82 | + { |
| 83 | + "conf_path": "/etc/nginx/nginx.conf", |
| 84 | + "config_version": "<config version from GET response>", |
| 85 | + "configs": { |
| 86 | + "/etc/nginx": { |
| 87 | + "files": [{ |
| 88 | + "path": "nginx.conf", |
| 89 | + "contents": "<base64-encoded-content-here>" |
| 90 | + }] |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + ``` |
| 95 | + To remove a file, simply omit the `contents` field for that file in your `PATCH` request body, your `partial_update_config.json` might look like this: |
| 96 | + ```json |
| 97 | + { |
| 98 | + "conf_path": "/etc/nginx/nginx.conf", |
| 99 | + "config_version": "<config version from GET response>", |
| 100 | + "configs": { |
| 101 | + "/etc/nginx/conf.d": { |
| 102 | + "files": [{ |
| 103 | + "path": "default.conf" |
| 104 | + }] |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | + ``` |
| 109 | + Multiple updates can be made in a single `PATCH` request. For example, to update `nginx.conf` and remove `default.conf`, your `partial_update_config.json` might look like this: |
| 110 | + ```json |
| 111 | + { |
| 112 | + "conf_path": "/etc/nginx/nginx.conf", |
| 113 | + "config_version": "<config version from GET response>", |
| 114 | + "configs": { |
| 115 | + "/etc/nginx": { |
| 116 | + "files": [{ |
| 117 | + "path": "nginx.conf", |
| 118 | + "contents": "<base64-encoded-content-here>" |
| 119 | + }] |
| 120 | + }, |
| 121 | + "/etc/nginx/conf.d": { |
| 122 | + "files": [{ |
| 123 | + "path": "default.conf" |
| 124 | + }] |
| 125 | + } |
| 126 | + } |
| 127 | + } |
| 128 | + ``` |
0 commit comments