Fluxheim/文档/Reverse Proxy

Reverse Proxy

把 Fluxheim 放在应用服务器前面。Fluxheim 负责 TLS、headers、limits 和 upstream 选择。

Basic proxy

[[vhosts]]
name = "app"
hosts = ["app.example.com"]

[[vhosts.routes]]
path_prefix = "/"
action = "proxy"
upstreams = ["127.0.0.1:3000"]

Route 选择

功能在以下情况使用
path_exact某个 URL 需要精确 route。
path_prefix整个 URL subtree 转发到一个 backend。
strip_prefixBackend 不应看到公共 prefix。
rewrite_prefixBackend 期望不同的内部 prefix。
methods一个 route 只应接受选定 HTTP methods。

Path rewrite 示例

[[vhosts.routes]]
name = "api"
path_prefix = "/api/"
strip_prefix = "/api/"
rewrite_prefix = "/internal/"

[vhosts.routes.proxy]
upstreams = ["10.0.0.20:8080"]
connect_timeout_secs = 5
read_timeout_secs = 30
send_timeout_secs = 30

适用于浏览器应用程序的 CORS

仅当已知来源的浏览器应用程序必须调用此路由时才启用 CORS。

[headers.cors]
enabled = true
allow_origins = ["https://app.example.com"]
allow_methods = ["GET", "HEAD", "POST"]
allow_headers = ["authorization", "content-type"]
allow_credentials = true
max_age_secs = 600
  • Fluxheim 在本地回答有效的预检请求;被拒绝的预检将返回 403,但未到达应用程序。
  • 不要将通配符来源与凭据结合起来。
  • CORS 不是身份验证、授权或 CSRF 保护。

生产说明

  • 将应用保持在 loopback 或私有网络中。
  • 在暴露上传前设置 request body limits。
  • Use trusted proxy settings only for networks you control.
  • 当不同 paths 需要不同安全规则时,优先使用明确 routes,而不是一个大 fallback。
简体中文