Files
3x-ui/docs/content/docs/zh/operations/security.mdx
T
MHSanaei 9b91f0f42e docs: vendor the documentation site into the monorepo
Fold the standalone 3x-ui-docs project (Next.js 16 + Fumadocs, deployed to
docs.sanaei.dev) into docs/ so the panel and its documentation share a single
source of truth, the way sing-box keeps its docs in-tree. The old repo becomes
redundant and can be retired.

- Import the full site under docs/ (app, components, content, lib, public,
  scripts, config). The self-contained pnpm project sits alongside the existing
  engineering notes with no filename collisions.
- Re-point "Edit on GitHub" links from MHSanaei/3x-ui-docs to this repo's
  docs/content/docs path (docs/lib/shared.ts, docs/app/.../page.tsx).
- Add docs-ci.yml and docs-deploy.yml under .github/workflows/, scoped to
  docs/** and run with working-directory: docs, since GitHub only runs
  workflows from the repo-root .github/. deploy-static.yml's GitHub Pages
  publish (CNAME docs.sanaei.dev) carries over unchanged.

Follow-up (outside this commit): attach the docs.sanaei.dev custom domain to
this repository's Pages (or set the Vercel project's root directory to docs),
confirm the site is live from the monorepo, then delete MHSanaei/3x-ui-docs.
2026-07-07 23:07:14 +02:00

63 lines
2.9 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: 安全加固
description: 加固 3x-ui——面板认证与 2FA、Fail2ban IP 限制、防火墙规则、BBR,以及保持更新。
icon: ShieldCheck
---
代理面板是高价值目标。几层加固措施就能带来很大改善。
## 面板加固
- 强而唯一的凭据,并启用**双因素认证**(TOTP)。
- 使用非默认的面板端口,以及一个长且随机的 Web 根路径。
- 为面板启用 TLS(直接启用,或通过[反向代理](/docs/operations/reverse-proxy))。
- 内置的**登录限制器**会在某个 IP/用户名于 5 分钟内连续 5 次登录失败后将其封锁
(封锁 15 分钟),并且面板可以将自身的出站流量经由某个 outbound 路由出去。
完整的检查清单请参见[首次登录](/docs/guide/first-login)。
## Fail2ban 与 IP 限制
为每个客户端设置一个 **IP 限制**(参见[客户端](/docs/config/clients)),以限制同时使用的源
IP 数量。限制的执行由 **Fail2ban** 负责,3x-ui 会为你安装并配置好它(脚本安装时默认启用,
Docker 安装时通过 `XUI_ENABLE_FAIL2BAN=true` 启用)。
可从 `x-ui` 菜单(**22 — IP Limit Management**)进行管理:安装/配置、修改封锁时长
(默认 **30 分钟**)、封锁/解封某个 IP、查看封锁日志,以及检查状态。其底层机制如下:
- 该 jail 名为 **`3x-ipl`**;封锁日志位于 `/var/log/x-ui/3xipl.log` 与
`/var/log/x-ui/3xipl-banned.log`(也可通过 `x-ui banlog` 查看)。
- 封锁覆盖所有 TCP/UDP,**但不包括**你的 SSH 端口和面板端口,因此封锁不会把你
锁在服务器或面板之外。
<Callout type="warn">
在 Docker 上,Fail2ban 使用 `iptables` 进行封锁,这需要 `NET_ADMIN`(以及
`NET_RAW`)权能——`docker-compose.yml` 已授予这些权能。若使用裸的
`docker run`,请添加 `--cap-add=NET_ADMIN --cap-add=NET_RAW`,否则封锁只会被
记录但永远不会真正生效。
</Callout>
## 防火墙
只开放你实际使用的端口:SSH、面板端口、订阅端口以及你的入站端口。`x-ui` 菜单
(**23 — Firewall Management**)封装了 `ufw`,或者你也可以在此生成规则:
<FirewallRulesGenerator />
<Callout type="warn">
在启用默认拒绝(default-deny)的防火墙之前,请确保 SSH 始终处于放行状态,否则你
可能把自己锁在外面。请在保留第二个会话的情况下进行测试。
</Callout>
## 网络调优(BBR)
`x-ui` 菜单(**26 — Enable BBR**)用于切换 Google 的 BBR 拥塞控制算法
(`net.ipv4.tcp_congestion_control = bbr`、`net.core.default_qdisc = fq`),它在拥塞链路
上通常能提升吞吐量。
## 保持更新
定期更新 3x-ui 和 Xray-core——安全修复会随新版本发布。请关注
[发布页面](https://github.com/MHSanaei/3x-ui/releases),并参见
[更新与卸载](/docs/guide/update-uninstall)。