# ngx\_http\_addition\_module

* [示例配置](/nginx-docs/he-xin-gong-neng/http/ngx_http_addition_module.md#example_configuration)
* [指令](/nginx-docs/he-xin-gong-neng/http/ngx_http_addition_module.md#directives)
  * [add\_before\_body](/nginx-docs/he-xin-gong-neng/http/ngx_http_addition_module.md#add_before_body)
  * [add\_after\_body](/nginx-docs/he-xin-gong-neng/http/ngx_http_addition_module.md#add_after_body)
  * [addition\_types](/nginx-docs/he-xin-gong-neng/http/ngx_http_addition_module.md#addition_types)

`ngx_http_addition_module` 是一个过滤器，用于在响应之前和之后添加文本。该模块不是默认构建，要启用应使用 `--with-http_addition_module` 配置参数构建。

## 示例配置 <a href="#example_configuration" id="example_configuration"></a>

```
location / {
    add_before_body /before_action;
    add_after_body  /after_action;
}
```

## 指令 <a href="#directives" id="directives"></a>

### add\_before\_body

| -       | 说明                           |
| ------- | ---------------------------- |
| **语法**  | **add\_before\_body** `uri`; |
| **默认**  | ——                           |
| **上下文** | http、server、location         |

在响应正文之前添加文本，作为给定子请求的一个处理结果返回。空字符串（`""`）作为参数时将取消从先前配置级别继承的额外文本。

### add\_after\_body

| -       | 说明                          |
| ------- | --------------------------- |
| **语法**  | **add\_after\_body** `uri`; |
| **默认**  | ——                          |
| **上下文** | http、server、location        |

在响应正文之后添加文本，作为给定子请求的一个处理结果返回。空字符串（`""`）作为参数时将取消从先前配置级别继承的额外文本。

### addition\_types

| -       | 说明                                   |
| ------- | ------------------------------------ |
| **语法**  | **addition\_types** `mime-type ...`; |
| **默认**  | addition\_types text/html;           |
| **上下文** | http、server、location                 |
| **提示**  | 该指令在 0.7.9 版本中出现                     |

除了 `text/html` 外，允许您在指定的 MIME 类型的响应中添加文本。特殊值 `*` 匹配所有 MIME类型（0.8.29）。

## 原文档

<http://nginx.org/en/docs/http/ngx_http_addition_module.html>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docshome.gitbook.io/nginx-docs/he-xin-gong-neng/http/ngx_http_addition_module.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
