# 替换响应内容

## http\_sub\_module

对http响应内容的替换。

```nginx
# 针对指定内容进行替换，将string替换为replacement
Syntax: sub_filter string replacement;
Default:
Context: http, server, location

# 指定匹配方式，匹配以此还是每个都匹配，默认匹配一次
Syntax: sub_filter_once on | off;
Default: sub_filter_once on;
Context: http, server, location

# nginx服务端与客户端，进行每次请求时校验服务端的内容是否发生变化
# last_modified 记录了时间，判断服务端数据是否更新，从而保证数据最新，常用于缓存场景
Syntax: sub_filter_last_modified on | off;
Default: sub_filter_last_modified off;
Context: http, server, location
```

**实例：**

```nginx
location / {
    root html;
	# 所有都替换
    sub_filter_once off;
    # 将所有hello 替换为 HELLO
    sub_filter 'hello' 'HELLO';
}
```


---

# 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://yangsx95.gitbook.io/notes/distributed/web-fu-wu-qi/nginx/ti-huan-xiang-ying-nei-rong.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.
