介绍
反向代理工具, 但是无法直接作为静态文件服务器
静态配置参考
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| api:
dashboard: true
entryPoints:
http:
address: ":80"
https:
address: ":443"
providers:
docker:
endpoint: "unix:///var/run/docker.sock"
exposedByDefault: false
file:
filename: /configurations/dynamic.yml
consul:
endpoints:
- consul:8500
rootKey: traefik
consulCatalog:
endpoint:
address: consul:8500
|
动态配置参考
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| http:
routers:
middlewares:
path-rewrite:
replacepathregex:
regex: "/v1/(.*)/"
replacement: "/"
gzip:
compress: true
cache-header:
headers:
customResponseHeaders:
Cache-Control: "public, max-age=31536000, immutable" # cache for 1 year
api-replace-path:
replacePathRegex:
regex: "^/api/(.*)"
replacement: "/v1/$1" # replace prefix /api/ to /v1/
tls:
options:
default:
cipherSuites:
- TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
- TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
- TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
- TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
- TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305
- TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305
minVersion: VersionTLS12
|
中间件
| 中间件 | 目的 | 区域 |
|---|
| 添加前缀 (AddPrefix) | 添加路径前缀 | 路径修改器 |
| 基本认证 (BasicAuth) | 添加基本 | 身份验证 安全、认证 |
| 缓冲 (Buffering) | 缓冲请求 | 响应 请求生命周期 |
| 链 (Chain) | 组合多个中间件 | 杂项 |
| 断路器 (CircuitBreaker) | 防止调用不健康的服务 | 请求生命周期 |
| 压缩 (Compress) | 压缩响应 | 内容修饰符 |
| 内容类型 (ContentType) | 处理 | Content-Type 自动检测 杂项 |
| 摘要认证 (DigestAuth) | 添加摘要身份验证 | 安全、认证 |
| 错误 (Errors) | 定义自定义错误页面 | 请求生命周期 |
| 转发验证 (ForwardAuth) | 代表身份验证 | 安全、认证 |
| 标头 (Headers) | 添加 | 更新标题 安全 |
| IP白名单 (IPWhiteList) | 限制允许的客户端 | IP 安全、请求生命周期 |
| 飞行请求 (InFlightReq) | 限制同时连接的数量 | 安全、请求生命周期 |
| 通过TLSClientCert (PassTLSClientCert) | 在标头中添加客户端证书 | 安全 |
| 速率限制 (RateLimit) | 限制呼叫频率 | 安全、请求生命周期 |
| 重定向方案 (RedirectScheme) | 基于方案的重定向 | 请求生命周期 |
| 重定向正则表达式 (RedirectRegex) | 基于正则表达式的重定向 | 请求生命周期 |
| 替换路径 (ReplacePath) | 更改请求的路径 | 路径修改器 |
| 替换路径正则表达式 (ReplacePathRegex) | 更改请求的路径 | 路径修改器 |
| 重试 (Retry) | 发生错误时自动重试 | 请求生命周期 |
| 带前缀 (StripPrefix) | 更改请求的路径 | 路径修改器 |
| 带前缀正则表达式 (StripPrefixRegex) | 更改请求的路径 | 路径修改器 |
七牛云CDN代理配置参考
七牛没有提供cdn缓存, 可以自己通过代理+缓存来实现
地址如下 https://cdn.staticfile.net
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
| # 动态配置文件 dynamic.yml
http:
routers:
cdn-static-router:
rule: "PathPrefix(`/cdn`)"
service: qiniu-cdn-service
middlewares:
- cache-header
- qiniu-cdn-replace-path
services:
qiniu-cdn-service:
loadBalancer:
servers:
- url: "https://cdn.staticfile.net"
# 必须有这行, 不然会403
passHostHeader: false
middlewares:
cache-header:
headers:
customResponseHeaders:
Expires: ""
Pragma: ""
Cache-Control: "public, max-age=31536000, immutable" # cache for 1 year
qiniu-cdn-replace-path:
replacePathRegex:
regex: "^/cdn/(.*)"
replacement: "/$1"
strip-forwarded-headers:
headers:
customRequestHeaders:
X-Forwarded-For: "" # 清空 X-Forwarded-For
X-Forwarded-Host: "" # 清空 X-Forwarded-Host
X-Forwarded-Port: "" # 清空 X-Forwarded-Port
X-Forwarded-Proto: "" # 清空 X-Forwarded-Proto
X-Forwarded-Scheme: "" # 清空 X-Forwarded-Scheme
|