post_action

The `post_action` directive specifies a handler to be executed after a response is sent to the client.

Syntaxpost_action uri;
Defaultnone
Contexthttp, server, location, if in location
Arguments1

Description

The post_action directive in NGINX allows you to specify an additional action that should be executed after a request has been processed. This directive can be defined at various levels within the NGINX configuration, such as http, server, location, or within 'if' statements inside a location block, providing flexibility according to different needs in handling HTTP requests. The primary purpose of this directive is to allow for subsequent processing tasks that do not affect the immediate response to the client, such as logging, notification, or additional background processing.

When you use the post_action directive, the specified URI will be requested after the main request has been fulfilled, potentially sending a background request to another endpoint. However, it is important to ensure that this endpoint is appropriately handled, as NGINX does not wait for the completion of the post_action; it merely triggers it after the main response is processed. This allows for operations that are not critical to the user's experience but might be essential for auditing or system maintenance purposes.

The directive takes one argument, which is the URI that the post-action will request. Keep in mind that the URI can include query parameters and should relate directly to a valid location block defined in the NGINX configuration.

Config Example

location /example {
    post_action /post-handler;
}

Ensure that the URI specified in post_action exists and can be accessed by NGINX, otherwise, it may lead to unexpected behavior.

post_action does not wait for the backend processing to complete; any necessary cleanup should be handled within the post-action itself.

← Back to all directives