Skip to content

Reverse Proxy

一句话解释

reverse proxy 是服务器那个接收客户端请求 and forwards 它们到 backend 服务器, 然后返回响应.

用大白话说

A reverse proxy is a server that sits between clients and your backend servers. Clients send requests to the proxy, and the proxy forwards them to the appropriate backend server, then returns the response.

Unlike a forward proxy (which sits between clients and the internet, used for anonymity), a reverse proxy sits in front of your servers. Common reverse proxies include nginx, HAProxy, and Traefik.

Reverse proxies provide several benefits: load balancing (distributing traffic), TLS termination (handling HTTPS so backends don't have to), caching (serving cached responses), compression, and routing (directing requests to different services based on path or host).

示例

nginx
server {
    listen 80;
    server_name example.com;

    location /api/ {
        proxy_pass http://api-server:3000/;
    }

    location / {
        proxy_pass http://web-server:80/;
    }
}

这个 nginx 配置 routes /API/ 请求到 API 服务器 and 一切 else 到 web 服务器.

工作原理

  1. A client sends a request to the reverse proxy.
  2. The proxy decides which backend server should handle it.
  3. It forwards the request to that backend.
  4. The backend returns the response to the proxy, which returns it to the client.

常见混淆

  • 容易混淆的对象: 向前 Proxy

    关键区别: reverse proxy sits in 前面的 服务器 and handles incoming traffic; 向前 proxy sits in 前面的 客户端 and handles outgoing traffic.

相关术语

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表