# 22. 代理

代理服务器是在客户端和后端服务器之间的中转服务器。客户端连接代理服务器请求网页、文件、连接等服务。简而言之，[代理服务器](https://en.wikipedia.org/wiki/Proxy_server)是一份软件或硬件，其作用是作为媒介处理客户端从其他服务器上寻找资源所发送的请求。

通常，代理的作用是过滤请求、记录请求或有时转换请求（添加/删除标头、编码/解码或压缩资源）。代理服务器的另一个优势是其缓存可以处理大量请求。如果多个客户端访问一个特定资源，代理服务器可以将该资源缓存，并用其服务所有的客户端，不需要访问远程服务器。

![](https://github.com/wat1r/Grokking-System-Design/blob/main/ch22_1.png)

## 1. 代理服务器类型

代理可以位于客户端本地服务器或者在客户端和远程服务器之间的任何位置。以下是一些著名的代理服务器的例子：

### 开放代理

[开放代理](https://en.wikipedia.org/wiki/Open_proxy)是可以被任何因特网用户访问的代理服务器。通常，代理服务器只允许一个网络组（及封闭代理）内的用户存储和转发因特网服务，如域名系统或网页，以减少或控制该网络组使用的带宽。但是使用开放代理时，因特网中的任何用户可以使用该代理转发服务。有两种著名的开放代理类型：

1. **匿名代理**——这种代理的特征是服务器，但是不透露初始 IP 地址。虽然这种代理服务器可以很容易被发现，但是对于一些用户是有用的，因为隐藏了 IP 地址。
2. **透明代理**——这种代理服务器再次识别自身，并且在 HTTP 标头的支持下，初始 IP 地址可以被看到。使用这种代理服务器的主要好处是可以缓存网站。

### 反向代理

[反向代理](https://en.wikipedia.org/wiki/Reverse_proxy)代表客户端从一台或多台服务器检索资源。然后这些资源被返回给客户端，如同这些资源是从代理服务器自身发出的。


---

# 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://cnwangzhou.gitbook.io/grokking-system-design/ch22.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.
