GET /api/users HTTP/1.1
Host: example.com
User-Agent: curl/7.68.0
Accept: application/json
Authorization: Bearer <token>
(空行)
(可选请求体)
| 范围 | 含义 | 常见 |
|---|---|---|
| 1xx | 信息 | 101 Switching Protocols |
| 2xx | 成功 | 200 OK, 201 Created, 204 No Content |
| 3xx | 重定向 | 301 永久, 302 临时, 304 Not Modified |
| 4xx | 客户端错误 | 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found |
| 5xx | 服务端错误 | 500 Internal Error, 502 Bad Gateway, 503 Unavailable, 504 Gateway Timeout |
| 版本 | 特点 |
|---|---|
| HTTP/1.0 | 每次请求新建连接 |
| HTTP/1.1 | 持久连接 (Keep-Alive)、管道化 |
| HTTP/2 | 多路复用、头部压缩、Server Push |
| HTTP/3 | 基于 QUIC (UDP),0-RTT 握手 |
客户端 → ClientHello (支持的加密套件)
服务端 ← ServerHello + 证书
客户端 → 密钥交换 → 对称加密通信
| 层级 | 依据 | 工具 |
|---|---|---|
| L4 (传输层) | IP + Port | LVS、Nginx stream、HAProxy tcp |
| L7 (应用层) | HTTP Header/Path/Cookie | Nginx http、HAProxy http、Envoy |
| 算法 | 说明 | 适用场景 |
|---|---|---|
| Round Robin | 轮询 | 后端能力相当 |
| Least Connections | 最少连接 | 长连接服务 |
| IP Hash | 按客户端 IP 哈希 | 会话保持 |
| Weighted | 加权 | 后端配置不均 |
upstream backend {
least_conn;
server 10.0.1.1:8080 weight=3;
server 10.0.1.2:8080 weight=1;
server 10.0.1.3:8080 backup;
}
server {
listen 80;
location / {
proxy_pass http://backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}