Set Up Proxy Request Buffers

Learn how to use NGINX Management Suite API Connectivity Manager to configure buffers for your API Gateway.


This documentation applies to NGINX Management Suite API Connectivity Manager 1.3.0 and later.

Overview

In NGINX Management Suite API Connectivity Manager (ACM), you can apply global policies to API Gateway and Developer Portal clusters to ensure your organization’s security requirements are enforced.

When you add policies at the environment level, they will apply to all proxies hosted within that environment.

See the Learn about Policies topic for an overview of the different policy types and available policies.


Proxy Buffers

See Also:
See the Module ngx_http_proxy_module topic for more information about the directives mentioned in this section.

When buffering is enabled, NGINX receives a response from the proxied server as soon as possible, saving it into the buffers set by the proxy_buffer_size and proxy_buffers directives.

  • The proxy_buffer_size directive is 4 KB or 8 KB, depending on the operating system. This directive sets the buffer size for reading the first part of the response received from the proxied server. This part usually contains a small response header. By default, the buffer size is equal to one memory page.

  • The proxy_buffers directive controls the size and the number of buffers allocated for a request. Increasing the number of buffers lets you buffer more information.

If the complete response doesn’t fit into memory, a part of it can be saved to a temporary file on the disk. The default max size of this temporary file is 1024 MB, and the default write size is 8 KB or 16 KB, depending on the operating system.

When configuring proxy buffers, the total size of the proxy_buffers (number * size) must be greater than the size of the proxy_busy_buffers_size minus one buffer. The default proxy_busy_buffers_size is 8 KB or 16 KB, depending on the operating system.

If you get the error [emerg] \"proxy_busy_buffers_size\" must be less than the size of all \"proxy_buffers\" minus one buffer in NGINX in the data plane, it is because the proxy buffer total number and size are configured incorrectly.

Examples

Example valid Proxy Buffers number and size
proxy busy buffers size : 16 KB
proxy buffer number     : 8 
proxy buffer size       : 4 KB
total buffer size       : 32 KB

busy_buffers_size < total buffer size - buffer
16 KB < 32 KB - 4 KB
16 KB < 28 KB
True: Valid proxy buffer number & size configuration
Example invalid proxy buffers number and size
proxy busy buffers size : 16 KB
proxy buffer number     : 2 
proxy buffer size       : 2k
total buffer size       : 8 KB

busy_buffers < total buffer size - buffer
16 KB < 8 KB - 2k
16 KB < 6k
False: Invalid proxy buffer number & size configuration

Tuning Proxy Buffers Number and Size

When using proxy buffering, we recommend that the complete response from upstream can be held in memory to avoid reading or writing to disk which is significantly slower.

If the response from upstream arrives fast and the client is slower, NGINX preserves the response in buffers, allowing it to close the upstream connection quickly.

If the allocated buffer size doesn’t allow storing the complete response in memory, it will be stored on disk, which is slower.

Fine-tuning the proxy_buffers number and size depends on the body response size of your application.

To determine the size of the HTML/data returned by a resource, you can use the following command:

curl -so /dev/null https://nginx.org/ -w '%{size_download}'

Set proxy_buffers in a way that it equals the total maximum size of response data.

For example, if the uncompressed body size is 8955 bytes (72 KB), you must set 72 KB worth of buffer size, either 18 4-KB-sized buffers or 9 8-KB-sized buffers.


Before You Begin

Complete the following prerequisites before proceeding with this guide:

  • API Connectivity Manager is installed, licensed, and running.
  • You have one or more Environments with API Gateway or Dev Portal clusters.
  • You have published one or more API Gateways

How to Access the User Interface

This guide provides instructions for completing tasks using the NGINX Management Suite API Connectivity Manager user interface (UI).

To access the UI, go to the FQDN of your NGINX Management Suite host and log in. On the Launchpad menu, select “API Connectivity Manager.”

How to Access the REST API

You can use tools such as curl or Postman to interact with the NGINX Management Suite API Connectivity Manager REST API. The API URL follows the format https://<NMS_FQDN>/api/acm/<API_VERSION>.

When making API calls by using curl, Postman, or any other tool, you need to provide your authentication information with each call. Refer to the API Overview for more information about authentication options.


Configuring Proxy Buffers in ACM

Follow the steps in this section to configure buffers for your API Gateway.

  1. In the ACM user interface, select Services > {{yourWorkspace}}, where yourWorkspace is the workspace that contains the API Gateway or Dev Portal.
  2. Select Edit Advanced Config on the Actions menu for the desired API Gateway or Dev Portal.
  3. On the Policies tab, select HTTP Backend Config, then select Add Policy on the Actions menu.
  4. Under Buffer Settings, enable the Add a queue toggle.
  5. Type the Number of buffers required and the associated Size. Note: The buffer Size uses NGINX’s unit of size measurement.

  1. Send a POST request to add the Backend Config policy to the API-Proxy.
Method Endpoint
POST /services/workspaces/<SERVICE_WORKSPACE_NAME>/proxies
JSON request
{
    "name": "{{proxyName}}",
    "version": "v1",
    "proxyConfig": {
        "hostname": "{{environmentHostname}}",
        "ingress": {
            "basePath": "/api"
        },
        "backends": [
            {
                "serviceName": "backend-svc",
                "serviceTargets": [
                    {
                        "hostname": "10.0.0.10"
                    }
                ]
            }
        ],
        "policies": {
            "backend-config": [
                {
                    "action": {
                        "buffer": {
                            "number": 42,
                            "size": "16 KB"
                        }
                    }
                }
            ]
        }
    }
}

 

UI Field API Parameter Datatype Possible Values Description Required
buffer.number action.buffer.number integer Example: 42 Sets the number of buffers used for reading a response from the proxied server for a single connection. Minimum value 2. True
buffer.size action.buffer.size string Example: 16k Sets the size of the buffers used for reading a response from the proxied server for a single connection. Follows NGINX configuration file measurement units syntax. Minimum value 1k. True