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_prefix | Backend 不應看到公共 prefix。 |
rewrite_prefix | Backend 期望不同的內部 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。