<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"><channel>
<title>fexumo</title>
<link>https://blog.fexumo.org</link>
<description>fexumo 的文章：Rust、技术与极简主义。</description>
<language>zh-CN</language>
<item>
<title>AnyTLS 部署指南（sing-box）</title>
<link>https://blog.fexumo.org/post/anytls-deploy</link>
<guid isPermaLink="true">https://blog.fexumo.org/post/anytls-deploy</guid>
<pubDate>Fri, 11 Sep 2026 00:00:00 GMT</pubDate>
<description>&lt;blockquote&gt;
&lt;p&gt;证书两种方案任选其一：&lt;strong&gt;ACME 自动申请&lt;/strong&gt;（推荐，需域名）或&lt;strong&gt;自签名证书&lt;/strong&gt;。ACME 使用 &lt;code&gt;certificate_providers&lt;/code&gt; 写法，需要 sing-box &lt;strong&gt;1.14.0+&lt;/strong&gt;。AnyTLS 占用 &lt;strong&gt;TCP 443&lt;/strong&gt;，不能用 TLS-ALPN 挑战（会与入站抢端口），用 &lt;strong&gt;HTTP-01（TCP 80）或 DNS-01&lt;/strong&gt;。用 IP 申请会自动套用 Let's Encrypt shortlived 短期证书（约 6 天有效期、续期频繁），故推荐域名。自签名方案不要把 &lt;code&gt;insecure&lt;/code&gt; 当默认。字段说明见 &lt;a href=&quot;https://sing-box.sagernet.org/configuration/inbound/anytls/&quot;&gt;AnyTLS inbound&lt;/a&gt;。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;一-部署前准备&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#一-部署前准备&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;一、部署前准备&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;确认以下条件：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;VPS 使用 Debian、Ubuntu 等带 systemd 的 Linux 发行版，具备 root 或 &lt;code&gt;sudo&lt;/code&gt; 权限；官方安装脚本覆盖 &lt;strong&gt;deb / rpm / Arch / OpenWrt&lt;/strong&gt;；&lt;/li&gt;
&lt;li&gt;一个已解析到该 VPS 的域名，以及可接收邮件的邮箱（ACME 申请用）；&lt;/li&gt;
&lt;li&gt;云安全组和本机防火墙放行 TCP &lt;code&gt;443&lt;/code&gt;，且未被 Nginx、Caddy 等占用；ACME HTTP-01 还需放行 TCP &lt;code&gt;80&lt;/code&gt;——只改安全组不够；&lt;/li&gt;
&lt;li&gt;准备一个足够复杂的连接密码。&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;二-安装-sing-box&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#二-安装-sing-box&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;二、安装 sing-box&lt;/span&gt;&lt;/h2&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-1&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-1&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;curl -fsSL https://sing-box.app/install.sh | sh
sing-box version&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;输出中的版本号必须 ≥ 1.14.0，否则不认识 &lt;code&gt;certificate_providers&lt;/code&gt;。若要钉死版本：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-2&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-2&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;curl -fsSL https://sing-box.app/install.sh | sh -s -- --version 1.14.0&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;脚本会下载 sing-box、安装 systemd 服务（以 &lt;code&gt;sing-box&lt;/code&gt; 用户运行）并创建 &lt;code&gt;/etc/sing-box/&lt;/code&gt;。&lt;/p&gt;
&lt;h2 id=&quot;三-生成证书-二选一&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#三-生成证书-二选一&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;三、生成证书（二选一）&lt;/span&gt;&lt;/h2&gt;
&lt;h3 id=&quot;方案-a-acme-自动申请-推荐-使用域名&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#方案-a-acme-自动申请-推荐-使用域名&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;方案 A：ACME 自动申请（推荐，使用域名）&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;把域名解析到 VPS 后按第四章配置，sing-box 会自动完成证书签发与续期。挑战只能走 HTTP-01（TCP 80）或 DNS-01，&lt;strong&gt;不要用 TLS-ALPN&lt;/strong&gt;。&lt;/p&gt;
&lt;h3 id=&quot;方案-b-自签名证书&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#方案-b-自签名证书&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;方案 B：自签名证书&lt;/span&gt;&lt;/h3&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-3&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-3&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo openssl ecparam -name prime256v1 -genkey -noout \
  -out /etc/sing-box/server.key

sudo openssl req -x509 -nodes \
  -key /etc/sing-box/server.key \
  -out /etc/sing-box/server.crt \
  -subj &amp;quot;/CN=bing.com&amp;quot; \
  -addext &amp;quot;subjectAltName=DNS:bing.com&amp;quot; \
  -days 825

sudo chmod 600 /etc/sing-box/server.key
sudo chmod 644 /etc/sing-box/server.crt&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;CN=bing.com&lt;/code&gt; 只是示例伪装名，不代表证书由 Bing 签发。&lt;code&gt;-addext&lt;/code&gt; 给证书附加 subjectAltName（SAN）——把证书导入客户端信任列表并启用严格校验时，SAN 必须与 &lt;code&gt;server_name&lt;/code&gt; 一致。有效期用 825 天，避免部分客户端拒绝「过长有效期」的证书。密钥用 P-256，不要改成 Ed25519。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;使用此方案时删除 &lt;code&gt;certificate_providers&lt;/code&gt; 段，&lt;code&gt;tls&lt;/code&gt; 段改为：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-4&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-4&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;&amp;quot;tls&amp;quot;: {
  &amp;quot;enabled&amp;quot;: true,
  &amp;quot;certificate_path&amp;quot;: &amp;quot;/etc/sing-box/server.crt&amp;quot;,
  &amp;quot;key_path&amp;quot;: &amp;quot;/etc/sing-box/server.key&amp;quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;客户端应导入该证书并保持 &lt;code&gt;insecure&lt;/code&gt; 为关闭。&lt;code&gt;&amp;quot;insecure&amp;quot;: true&lt;/code&gt; 等于放弃证书校验，任意中间人可冒充服务端，只适合临时排障。&lt;/p&gt;
&lt;h2 id=&quot;四-写入服务端配置&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#四-写入服务端配置&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;四、写入服务端配置&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;将下面的配置写入 &lt;code&gt;/etc/sing-box/config.json&lt;/code&gt;：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-5&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-5&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;{
  &amp;quot;log&amp;quot;: {
    &amp;quot;level&amp;quot;: &amp;quot;info&amp;quot;,
    &amp;quot;timestamp&amp;quot;: true
  },
  &amp;quot;certificate_providers&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;acme&amp;quot;,
      &amp;quot;tag&amp;quot;: &amp;quot;acme_cert&amp;quot;,
      &amp;quot;domain&amp;quot;: [
        &amp;quot;YOUR_DOMAIN&amp;quot;
      ],
      &amp;quot;email&amp;quot;: &amp;quot;YOUR_EMAIL@example.com&amp;quot;,
      &amp;quot;data_directory&amp;quot;: &amp;quot;/var/lib/sing-box/certmagic&amp;quot;
    }
  ],
  &amp;quot;inbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;anytls&amp;quot;,
      &amp;quot;listen&amp;quot;: &amp;quot;::&amp;quot;,
      &amp;quot;listen_port&amp;quot;: 443,
      &amp;quot;users&amp;quot;: [
        {
          &amp;quot;password&amp;quot;: &amp;quot;CHANGE_THIS_TO_A_STRONG_PASSWORD&amp;quot;
        }
      ],
      &amp;quot;tls&amp;quot;: {
        &amp;quot;enabled&amp;quot;: true,
        &amp;quot;server_name&amp;quot;: &amp;quot;YOUR_DOMAIN&amp;quot;,
        &amp;quot;certificate_provider&amp;quot;: &amp;quot;acme_cert&amp;quot;
      }
    }
  ],
  &amp;quot;outbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;direct&amp;quot;
    }
  ]
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;&lt;code&gt;data_directory&lt;/code&gt; 必须落在官方服务的 &lt;code&gt;StateDirectory&lt;/code&gt;（&lt;code&gt;/var/lib/sing-box&lt;/code&gt;）下。省略时 ACME 数据跟 &lt;code&gt;sing-box&lt;/code&gt; 用户的 &lt;code&gt;HOME&lt;/code&gt; 走，重启后可能丢证书或写不进去。&lt;/p&gt;
&lt;h3 id=&quot;必须修改的字段&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#必须修改的字段&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;必须修改的字段&lt;/span&gt;&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;配置项&lt;/th&gt;
&lt;th&gt;修改为&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;certificate_providers[0].domain[0]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;你的域名（需解析到该 VPS）&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;certificate_providers[0].email&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;你的邮箱地址&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;inbounds[0].users[0].password&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;高强度连接密码&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;inbounds[0].tls.server_name&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;与证书所用的域名相同&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;inbounds[0].listen&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;默认 &lt;code&gt;::&lt;/code&gt;。机器禁用 IPv6 时改为 &lt;code&gt;0.0.0.0&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;YOUR_DOMAIN&lt;/code&gt; 必须在 &lt;code&gt;domain[0]&lt;/code&gt; 和 &lt;code&gt;tls.server_name&lt;/code&gt; 两处保持一致，且已解析到当前 VPS；密码不要继续使用示例值。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;建议限制配置文件权限：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-6&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-6&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo chmod 600 /etc/sing-box/config.json&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h3 id=&quot;可选字段说明&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#可选字段说明&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;可选字段说明&lt;/span&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;padding_scheme&lt;/code&gt;：服务端填充方案，客户端无需配置；留空时使用内置默认方案，一般无需修改；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;users[].name&lt;/code&gt;：可选字段，仅用于日志中区分用户。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;客户端不要设置 &lt;code&gt;client_metadata&lt;/code&gt;。1.13.16 起默认留空，避免被对端画像；不要为了「完整」把它加回去。&lt;/p&gt;
&lt;h2 id=&quot;五-检查并启动&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#五-检查并启动&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;五、检查并启动&lt;/span&gt;&lt;/h2&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-7&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-7&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo sing-box check -c /etc/sing-box/config.json
sudo systemctl enable sing-box
sudo systemctl restart sing-box
sudo systemctl status sing-box --no-pager&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;&lt;code&gt;check&lt;/code&gt; 没有输出且退出码为 &lt;code&gt;0&lt;/code&gt; 表示配置通过。&lt;code&gt;status&lt;/code&gt; 应为 &lt;code&gt;active (running)&lt;/code&gt;；否则查看日志：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-8&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-8&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo journalctl -u sing-box --output cat -e&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;六-服务管理&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#六-服务管理&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;六、服务管理&lt;/span&gt;&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;操作&lt;/th&gt;
&lt;th&gt;命令&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;查看状态&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl status sing-box --no-pager&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;启动&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl start sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;停止&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl stop sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;重启&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl restart sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;禁用开机自启&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl disable sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;查看最近日志&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo journalctl -u sing-box --output cat -e&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;实时查看日志&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo journalctl -u sing-box --output cat -f&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;七-客户端配置参考&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#七-客户端配置参考&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;七、客户端配置参考&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;下面是一份&lt;strong&gt;可直接 &lt;code&gt;sing-box check&lt;/code&gt; 的最小客户端配置&lt;/strong&gt;：本地 &lt;code&gt;mixed&lt;/code&gt; 入站 + 一个出站。出站必须放在 &lt;code&gt;outbounds&lt;/code&gt; 数组里，不能把出站对象单独当成完整配置文件。&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-9&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-9&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;{
  &amp;quot;log&amp;quot;: {
    &amp;quot;level&amp;quot;: &amp;quot;info&amp;quot;,
    &amp;quot;timestamp&amp;quot;: true
  },
  &amp;quot;inbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;mixed&amp;quot;,
      &amp;quot;listen&amp;quot;: &amp;quot;127.0.0.1&amp;quot;,
      &amp;quot;listen_port&amp;quot;: 1080
    }
  ],
  &amp;quot;outbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;anytls&amp;quot;,
      &amp;quot;tag&amp;quot;: &amp;quot;anytls-out&amp;quot;,
      &amp;quot;server&amp;quot;: &amp;quot;YOUR_SERVER_IP&amp;quot;,
      &amp;quot;server_port&amp;quot;: 443,
      &amp;quot;password&amp;quot;: &amp;quot;CHANGE_THIS_TO_A_STRONG_PASSWORD&amp;quot;,
      &amp;quot;tls&amp;quot;: {
        &amp;quot;enabled&amp;quot;: true,
        &amp;quot;server_name&amp;quot;: &amp;quot;YOUR_DOMAIN&amp;quot;
      }
    }
  ]
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;本机 SOCKS / HTTP 代理为 &lt;code&gt;127.0.0.1:1080&lt;/code&gt;。&lt;/p&gt;
&lt;p&gt;要点：&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;客户端字段&lt;/th&gt;
&lt;th&gt;说明&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;server&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;VPS 公网 IP&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;password&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;与服务端 &lt;code&gt;users[0].password&lt;/code&gt; 完全一致&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tls.server_name&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;与服务端 &lt;code&gt;tls.server_name&lt;/code&gt; 一致，即证书申请所用的域名&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;blockquote&gt;
&lt;p&gt;服务端使用 ACME 签发的公网受信证书时，客户端不要设置 &lt;code&gt;insecure&lt;/code&gt;。使用自签名证书（方案 B）时，把服务端证书导入客户端信任列表，而不是打开 &lt;code&gt;insecure&lt;/code&gt;。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;八-故障排查&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#八-故障排查&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;八、故障排查&lt;/span&gt;&lt;/h2&gt;
&lt;h3 id=&quot;1-443-端口无法监听&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#1-443-端口无法监听&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;1. 443 端口无法监听&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;检查端口占用：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-10&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-10&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo ss -lntp | grep ':443'&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;如果已有 Nginx、Caddy 或其他 sing-box 实例监听 443，需要停止冲突服务，或修改 &lt;code&gt;listen_port&lt;/code&gt;。禁用 IPv6 时把 &lt;code&gt;listen&lt;/code&gt; 改为 &lt;code&gt;0.0.0.0&lt;/code&gt;。&lt;/p&gt;
&lt;h3 id=&quot;2-acme-证书申请失败&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#2-acme-证书申请失败&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;2. ACME 证书申请失败&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;重点检查：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;域名是否已解析到该 VPS（可用 &lt;code&gt;dig +short 你的域名&lt;/code&gt; 确认）；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;domain[0]&lt;/code&gt; 与 &lt;code&gt;tls.server_name&lt;/code&gt; 是否一致；&lt;/li&gt;
&lt;li&gt;TCP 80 是否放行、是否被占用（HTTP-01）；不要指望 TLS-ALPN，443 已被 AnyTLS 占用；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;data_directory&lt;/code&gt; 是否为 &lt;code&gt;/var/lib/sing-box/certmagic&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;系统时间是否准确；&lt;/li&gt;
&lt;li&gt;日志中是否出现证书申请或验证错误。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;3-修改配置后服务无法启动&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#3-修改配置后服务无法启动&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;3. 修改配置后服务无法启动&lt;/span&gt;&lt;/h3&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-11&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-11&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo sing-box check -c /etc/sing-box/config.json
sudo journalctl -u sing-box -n 100 --no-pager&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h3 id=&quot;4-客户端无法连接&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#4-客户端无法连接&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;4. 客户端无法连接&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;依次确认：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;systemctl status&lt;/code&gt; 为 &lt;code&gt;active (running)&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;VPS 防火墙和云安全组放行 TCP &lt;code&gt;443&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;客户端密码与 &lt;code&gt;users[0].password&lt;/code&gt; 完全一致；&lt;/li&gt;
&lt;li&gt;服务端日志中没有认证失败或证书错误。&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;九-安全建议&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#九-安全建议&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;九、安全建议&lt;/span&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;密码用长随机值，不要示例字符串；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;config.json&lt;/code&gt; 与 &lt;code&gt;server.key&lt;/code&gt; 权限 &lt;code&gt;600&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;优先 ACME 公网证书；自签要导入证书，不要长期开 &lt;code&gt;insecure&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;不要自定义 &lt;code&gt;client_metadata&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;定期升级 sing-box，升级后重新执行 &lt;code&gt;sing-box check&lt;/code&gt;。&lt;/li&gt;
&lt;/ul&gt;
</description>
</item>
<item>
<title>Hysteria2 部署指南（sing-box）</title>
<link>https://blog.fexumo.org/post/hysteria2-deploy</link>
<guid isPermaLink="true">https://blog.fexumo.org/post/hysteria2-deploy</guid>
<pubDate>Fri, 11 Sep 2026 00:00:00 GMT</pubDate>
<description>&lt;blockquote&gt;
&lt;p&gt;Hysteria2 基于 QUIC，服务端监听 &lt;strong&gt;UDP&lt;/strong&gt; 端口。证书两种方案任选其一：&lt;strong&gt;ACME 自动申请&lt;/strong&gt;（推荐，需域名）或&lt;strong&gt;自签名证书&lt;/strong&gt;。ACME 使用 &lt;code&gt;certificate_providers&lt;/code&gt; 写法，需要 sing-box &lt;strong&gt;1.14.0+&lt;/strong&gt;。入站是 UDP 443，TCP 443 空着，因此挑战可用 &lt;strong&gt;HTTP-01（TCP 80）或 TLS-ALPN（TCP 443）&lt;/strong&gt;。用 IP 申请会自动套用 Let's Encrypt shortlived 短期证书（约 6 天有效期、续期频繁），故推荐域名。自签名方案不要把 &lt;code&gt;insecure&lt;/code&gt; 当默认。字段说明见 &lt;a href=&quot;https://sing-box.sagernet.org/configuration/inbound/hysteria2/&quot;&gt;Hysteria2 inbound&lt;/a&gt; 与 &lt;a href=&quot;https://sing-box.sagernet.org/configuration/outbound/hysteria2/&quot;&gt;outbound&lt;/a&gt;。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;一-部署前准备&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#一-部署前准备&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;一、部署前准备&lt;/span&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;一台使用 systemd 的 Linux VPS，具备 root 或 &lt;code&gt;sudo&lt;/code&gt; 权限；官方安装脚本覆盖 &lt;strong&gt;deb / rpm / Arch / OpenWrt&lt;/strong&gt;；&lt;/li&gt;
&lt;li&gt;一个已解析到该 VPS 公网 IP 的域名，以及可接收邮件的邮箱（ACME 申请用）；&lt;/li&gt;
&lt;li&gt;云安全组和本机防火墙放行 &lt;strong&gt;UDP&lt;/strong&gt; &lt;code&gt;443&lt;/code&gt;，且未被其他服务占用；启用端口跳跃时还需放行整个 UDP 范围（如 &lt;code&gt;20000–40000&lt;/code&gt;），不是只放行 443 或 9443——只改安全组不够；&lt;/li&gt;
&lt;li&gt;使用 ACME 时按挑战方式放行对应 TCP 端口（HTTP-01 为 &lt;code&gt;80&lt;/code&gt;，TLS-ALPN 为 &lt;code&gt;443&lt;/code&gt;）；&lt;/li&gt;
&lt;li&gt;准备一个较长、随机的认证密码。&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;二-安装-sing-box&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#二-安装-sing-box&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;二、安装 sing-box&lt;/span&gt;&lt;/h2&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-1&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-1&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;curl -fsSL https://sing-box.app/install.sh | sh
sing-box version&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;输出中的版本号必须 ≥ 1.14.0，否则不认识 &lt;code&gt;certificate_providers&lt;/code&gt; / &lt;code&gt;gecko&lt;/code&gt; / &lt;code&gt;bbr_profile&lt;/code&gt;。若要钉死版本：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-2&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-2&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;curl -fsSL https://sing-box.app/install.sh | sh -s -- --version 1.14.0&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;脚本会下载 sing-box、安装 systemd 服务（以 &lt;code&gt;sing-box&lt;/code&gt; 用户运行）并创建 &lt;code&gt;/etc/sing-box/&lt;/code&gt;。&lt;/p&gt;
&lt;h2 id=&quot;三-生成证书-二选一&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#三-生成证书-二选一&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;三、生成证书（二选一）&lt;/span&gt;&lt;/h2&gt;
&lt;h3 id=&quot;方案-a-acme-自动申请-推荐-使用域名&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#方案-a-acme-自动申请-推荐-使用域名&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;方案 A：ACME 自动申请（推荐，使用域名）&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;配置见第四章；把域名解析到该 VPS 后自动完成证书签发与续期。HTTP-01 与 TLS-ALPN 都可以（后者走 TCP 443，与 UDP 443 不冲突）。&lt;/p&gt;
&lt;h3 id=&quot;方案-b-自签名证书&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#方案-b-自签名证书&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;方案 B：自签名证书&lt;/span&gt;&lt;/h3&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-3&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-3&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo openssl ecparam -name prime256v1 -genkey -noout \
  -out /etc/sing-box/server.key

sudo openssl req -x509 -nodes \
  -key /etc/sing-box/server.key \
  -out /etc/sing-box/server.crt \
  -subj &amp;quot;/CN=bing.com&amp;quot; \
  -addext &amp;quot;subjectAltName=DNS:bing.com&amp;quot; \
  -days 825

sudo chmod 600 /etc/sing-box/server.key
sudo chmod 644 /etc/sing-box/server.crt&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;CN=bing.com&lt;/code&gt; 只是示例伪装名，不代表证书由 Bing 签发。&lt;code&gt;-addext&lt;/code&gt; 给证书附加 SAN——导入客户端信任列表并严格校验时，SAN 必须与 &lt;code&gt;server_name&lt;/code&gt; 一致。有效期用 825 天，避免部分客户端拒绝过长有效期。密钥必须是 P-256（或 RSA）；&lt;strong&gt;不要用 Ed25519&lt;/strong&gt;——sing-box 1.14 客户端默认鹦鹉 Chrome QUIC，Chrome 不声明 Ed25519，握手会失败（ACME 证书不受影响）。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;使用此方案时删除 &lt;code&gt;certificate_providers&lt;/code&gt; 段，&lt;code&gt;tls&lt;/code&gt; 段改为：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-4&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-4&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;&amp;quot;tls&amp;quot;: {
  &amp;quot;enabled&amp;quot;: true,
  &amp;quot;certificate_path&amp;quot;: &amp;quot;/etc/sing-box/server.crt&amp;quot;,
  &amp;quot;key_path&amp;quot;: &amp;quot;/etc/sing-box/server.key&amp;quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;客户端应导入该证书并保持 &lt;code&gt;insecure&lt;/code&gt; 为关闭。&lt;code&gt;&amp;quot;insecure&amp;quot;: true&lt;/code&gt; 等于放弃证书校验，只适合临时排障。&lt;code&gt;server_name&lt;/code&gt; 填证书中的伪装域名（如 &lt;code&gt;bing.com&lt;/code&gt;）。&lt;/p&gt;
&lt;h2 id=&quot;四-写入服务端配置&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#四-写入服务端配置&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;四、写入服务端配置&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;将以下配置写入 &lt;code&gt;/etc/sing-box/config.json&lt;/code&gt;：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-5&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-5&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;{
  &amp;quot;log&amp;quot;: {
    &amp;quot;level&amp;quot;: &amp;quot;info&amp;quot;,
    &amp;quot;timestamp&amp;quot;: true
  },
  &amp;quot;certificate_providers&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;acme&amp;quot;,
      &amp;quot;tag&amp;quot;: &amp;quot;acme_cert&amp;quot;,
      &amp;quot;domain&amp;quot;: [
        &amp;quot;YOUR_DOMAIN&amp;quot;
      ],
      &amp;quot;email&amp;quot;: &amp;quot;YOUR_EMAIL@example.com&amp;quot;,
      &amp;quot;data_directory&amp;quot;: &amp;quot;/var/lib/sing-box/certmagic&amp;quot;
    }
  ],
  &amp;quot;inbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;hysteria2&amp;quot;,
      &amp;quot;listen&amp;quot;: &amp;quot;::&amp;quot;,
      &amp;quot;listen_port&amp;quot;: 443,
      &amp;quot;users&amp;quot;: [
        {
          &amp;quot;password&amp;quot;: &amp;quot;CHANGE_THIS_TO_A_STRONG_PASSWORD&amp;quot;
        }
      ],
      &amp;quot;tls&amp;quot;: {
        &amp;quot;enabled&amp;quot;: true,
        &amp;quot;server_name&amp;quot;: &amp;quot;YOUR_DOMAIN&amp;quot;,
        &amp;quot;certificate_provider&amp;quot;: &amp;quot;acme_cert&amp;quot;
      }
    }
  ],
  &amp;quot;outbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;direct&amp;quot;
    }
  ]
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;&lt;code&gt;data_directory&lt;/code&gt; 必须落在官方服务的 &lt;code&gt;StateDirectory&lt;/code&gt;（&lt;code&gt;/var/lib/sing-box&lt;/code&gt;）下。省略时 ACME 数据跟 &lt;code&gt;sing-box&lt;/code&gt; 用户的 &lt;code&gt;HOME&lt;/code&gt; 走，重启后可能丢证书或写不进去。&lt;/p&gt;
&lt;h3 id=&quot;必须修改的字段&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#必须修改的字段&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;必须修改的字段&lt;/span&gt;&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;配置项&lt;/th&gt;
&lt;th&gt;说明&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;certificate_providers[0].domain[0]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;你的域名（需解析到该 VPS）&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;certificate_providers[0].email&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;你的邮箱地址&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;users[0].password&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;客户端连接时使用的密码，必须修改&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tls.server_name&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;与 &lt;code&gt;domain[0]&lt;/code&gt; 保持一致&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;listen&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;默认 &lt;code&gt;::&lt;/code&gt;。机器禁用 IPv6 时改为 &lt;code&gt;0.0.0.0&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;YOUR_DOMAIN&lt;/code&gt; 必须在 &lt;code&gt;domain[0]&lt;/code&gt; 和 &lt;code&gt;tls.server_name&lt;/code&gt; 两处保持一致，且已解析到当前 VPS；密码不要继续使用示例值。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;可选字段说明&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#可选字段说明&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;可选字段说明&lt;/span&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;up_mbps&lt;/code&gt; / &lt;code&gt;down_mbps&lt;/code&gt;：&lt;strong&gt;服务端&lt;/strong&gt;向客户端下发 Brutal 速率上限；留空则不限速。与 &lt;code&gt;ignore_client_bandwidth&lt;/code&gt; 互斥；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ignore_client_bandwidth&lt;/code&gt;：仅服务端。未设置带宽时命令客户端改用 BBR；已设置带宽时禁止客户端用 BBR；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bbr_profile&lt;/code&gt;（1.14+）：BBR 档位，可选 &lt;code&gt;conservative&lt;/code&gt;、&lt;code&gt;standard&lt;/code&gt;、&lt;code&gt;aggressive&lt;/code&gt;，默认 &lt;code&gt;standard&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;obfs&lt;/code&gt;：QUIC 流量混淆，支持 &lt;code&gt;salamander&lt;/code&gt; 与 &lt;code&gt;gecko&lt;/code&gt;（1.14+），见下方示例；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;masquerade&lt;/code&gt;：认证失败时的 HTTP3 伪装响应，见下方示例；未配置时返回 404；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;users&lt;/code&gt;：密码认证；官方程序的 &lt;code&gt;userpass&lt;/code&gt; 写法在 sing-box 中需将 &lt;code&gt;username:password&lt;/code&gt; 整体作为密码。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;客户端出站自己的 &lt;code&gt;up_mbps&lt;/code&gt; / &lt;code&gt;down_mbps&lt;/code&gt; 是&lt;strong&gt;该客户端的带宽声明&lt;/strong&gt;：留空则该客户端使用 BBR，与服务端是否限速是两件事。&lt;/p&gt;
&lt;h3 id=&quot;可选-obfs-混淆示例&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#可选-obfs-混淆示例&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;可选：obfs 混淆示例&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;在入站中加入 &lt;code&gt;obfs&lt;/code&gt; 段（服务端与客户端的类型、密码必须完全一致）：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-6&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-6&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;&amp;quot;obfs&amp;quot;: {
  &amp;quot;type&amp;quot;: &amp;quot;salamander&amp;quot;,
  &amp;quot;password&amp;quot;: &amp;quot;OBFS_PASSWORD&amp;quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;使用 &lt;code&gt;gecko&lt;/code&gt;（1.14+）时把 &lt;code&gt;type&lt;/code&gt; 改为 &lt;code&gt;gecko&lt;/code&gt;，还可调整 &lt;code&gt;min_packet_size&lt;/code&gt;（默认 512）与 &lt;code&gt;max_packet_size&lt;/code&gt;（默认 1200）。&lt;/p&gt;
&lt;h3 id=&quot;可选-masquerade-伪装示例&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#可选-masquerade-伪装示例&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;可选：masquerade 伪装示例&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;对象写法（认证失败时反向代理到真实网站）：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-7&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-7&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;&amp;quot;masquerade&amp;quot;: {
  &amp;quot;type&amp;quot;: &amp;quot;proxy&amp;quot;,
  &amp;quot;url&amp;quot;: &amp;quot;https://www.bing.com/&amp;quot;,
  &amp;quot;rewrite_host&amp;quot;: true
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;也可以用字符串简写 &lt;code&gt;&amp;quot;masquerade&amp;quot;: &amp;quot;https://www.bing.com/&amp;quot;&lt;/code&gt;，或改用 &lt;code&gt;file&lt;/code&gt; 类型将 &lt;code&gt;directory&lt;/code&gt; 指向本地站点目录作为文件服务器。&lt;/p&gt;
&lt;p&gt;生成随机密码并设置配置文件权限：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-8&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-8&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;openssl rand -base64 32
sudo chmod 600 /etc/sing-box/config.json&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;五-检查并启动&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#五-检查并启动&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;五、检查并启动&lt;/span&gt;&lt;/h2&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-9&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-9&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo sing-box check -c /etc/sing-box/config.json
sudo systemctl enable sing-box
sudo systemctl restart sing-box
sudo systemctl status sing-box --no-pager&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;&lt;code&gt;check&lt;/code&gt; 没有输出且退出码为 &lt;code&gt;0&lt;/code&gt; 表示配置通过。&lt;code&gt;status&lt;/code&gt; 应为 &lt;code&gt;active (running)&lt;/code&gt;；否则查看日志：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-10&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-10&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo journalctl -u sing-box --output cat -e&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;六-服务管理&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#六-服务管理&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;六、服务管理&lt;/span&gt;&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;操作&lt;/th&gt;
&lt;th&gt;命令&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;查看状态&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl status sing-box --no-pager&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;启动&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl start sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;停止&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl stop sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;重启&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl restart sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;禁用开机自启&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl disable sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;查看最近日志&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo journalctl -u sing-box --output cat -e&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;实时查看日志&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo journalctl -u sing-box --output cat -f&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;七-客户端配置参考&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#七-客户端配置参考&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;七、客户端配置参考&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;下面是一份&lt;strong&gt;可直接 &lt;code&gt;sing-box check&lt;/code&gt; 的最小客户端配置&lt;/strong&gt;：本地 &lt;code&gt;mixed&lt;/code&gt; 入站 + 一个出站。出站必须放在 &lt;code&gt;outbounds&lt;/code&gt; 数组里，不能把出站对象单独当成完整配置文件。&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-11&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-11&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;{
  &amp;quot;log&amp;quot;: {
    &amp;quot;level&amp;quot;: &amp;quot;info&amp;quot;,
    &amp;quot;timestamp&amp;quot;: true
  },
  &amp;quot;inbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;mixed&amp;quot;,
      &amp;quot;listen&amp;quot;: &amp;quot;127.0.0.1&amp;quot;,
      &amp;quot;listen_port&amp;quot;: 1080
    }
  ],
  &amp;quot;outbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;hysteria2&amp;quot;,
      &amp;quot;tag&amp;quot;: &amp;quot;hy2-out&amp;quot;,
      &amp;quot;server&amp;quot;: &amp;quot;YOUR_SERVER_IP&amp;quot;,
      &amp;quot;server_port&amp;quot;: 443,
      &amp;quot;password&amp;quot;: &amp;quot;CHANGE_THIS_TO_A_STRONG_PASSWORD&amp;quot;,
      &amp;quot;tls&amp;quot;: {
        &amp;quot;enabled&amp;quot;: true,
        &amp;quot;server_name&amp;quot;: &amp;quot;YOUR_DOMAIN&amp;quot;
      }
    }
  ]
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;本机 SOCKS / HTTP 代理为 &lt;code&gt;127.0.0.1:1080&lt;/code&gt;。&lt;/p&gt;
&lt;p&gt;要点：&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;客户端字段&lt;/th&gt;
&lt;th&gt;说明&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;server&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;VPS 公网 IP&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;server_port&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;与服务端 &lt;code&gt;listen_port&lt;/code&gt; 一致；启用端口跳跃时改用 &lt;code&gt;server_ports&lt;/code&gt;，此时不要写 &lt;code&gt;server_port&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;password&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;与服务端 &lt;code&gt;users[0].password&lt;/code&gt; 完全一致&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tls.server_name&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;与服务端 &lt;code&gt;tls.server_name&lt;/code&gt; 一致，即证书申请所用的域名&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;blockquote&gt;
&lt;p&gt;ACME 公网受信证书不要加 &lt;code&gt;insecure&lt;/code&gt;。自签名（方案 B）应导入服务端证书；&lt;code&gt;server_name&lt;/code&gt; 填证书中的伪装域名（如 &lt;code&gt;bing.com&lt;/code&gt;）。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;服务端启用 &lt;code&gt;obfs&lt;/code&gt; 时，客户端需配置类型与密码一致的 &lt;code&gt;obfs&lt;/code&gt; 段。1.14 客户端默认鹦鹉 Chrome QUIC；服务端若误用 Ed25519 证书会握手失败，可在客户端设 &lt;code&gt;&amp;quot;disable_chrome_parrot&amp;quot;: true&lt;/code&gt; 做对比测试，生产环境应换 ECDSA/RSA 证书而不是关鹦鹉。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;八-配置端口跳跃-可选&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#八-配置端口跳跃-可选&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;八、配置端口跳跃（可选）&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;客户端用一个 UDP 端口范围连接，由 iptables 转发到实际服务端口。示例：跳跃端口 &lt;code&gt;20000:40000&lt;/code&gt;，实际监听 &lt;code&gt;9443&lt;/code&gt;，网卡 &lt;code&gt;eth0&lt;/code&gt;。&lt;/p&gt;
&lt;p&gt;安全组 / 防火墙必须放行 &lt;strong&gt;UDP 20000–40000&lt;/strong&gt;。DNAT 之后数据包打到本机 &lt;code&gt;9443&lt;/code&gt;，公网不必再放行 443 或 9443。&lt;/p&gt;
&lt;h3 id=&quot;1-修改监听端口&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#1-修改监听端口&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;1. 修改监听端口&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;将 &lt;code&gt;&amp;quot;listen_port&amp;quot;: 443&lt;/code&gt; 改为 &lt;code&gt;9443&lt;/code&gt;，并重启服务：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-12&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-12&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo systemctl restart sing-box&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h3 id=&quot;2-添加转发规则&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#2-添加转发规则&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;2. 添加转发规则&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;安装持久化工具并添加 IPv4 / IPv6 转发规则：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-13&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-13&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo apt update
sudo apt install -y iptables-persistent

sudo iptables -t nat -A PREROUTING -i eth0 -p udp --dport 20000:40000 -j DNAT --to-destination :9443
sudo ip6tables -t nat -A PREROUTING -i eth0 -p udp --dport 20000:40000 -j DNAT --to-destination :9443
sudo netfilter-persistent save&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;blockquote&gt;
&lt;p&gt;网卡不是 &lt;code&gt;eth0&lt;/code&gt; 时替换为实际接口名（&lt;code&gt;ip route get 1.1.1.1&lt;/code&gt; 可查看）；规则中的网卡、端口范围、目标端口须与实际配置一致，添加前建议先备份现有规则。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;3-客户端-端口跳跃&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#3-客户端-端口跳跃&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;3. 客户端（端口跳跃）&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;server_ports&lt;/code&gt; 与 &lt;code&gt;server_port&lt;/code&gt; 冲突，只保留范围。单元素时官方允许省略数组括号，写成字符串也可以：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-14&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-14&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;{
  &amp;quot;log&amp;quot;: {
    &amp;quot;level&amp;quot;: &amp;quot;info&amp;quot;,
    &amp;quot;timestamp&amp;quot;: true
  },
  &amp;quot;inbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;mixed&amp;quot;,
      &amp;quot;listen&amp;quot;: &amp;quot;127.0.0.1&amp;quot;,
      &amp;quot;listen_port&amp;quot;: 1080
    }
  ],
  &amp;quot;outbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;hysteria2&amp;quot;,
      &amp;quot;tag&amp;quot;: &amp;quot;hy2-out&amp;quot;,
      &amp;quot;server&amp;quot;: &amp;quot;YOUR_SERVER_IP&amp;quot;,
      &amp;quot;server_ports&amp;quot;: [
        &amp;quot;20000:40000&amp;quot;
      ],
      &amp;quot;hop_interval&amp;quot;: &amp;quot;30s&amp;quot;,
      &amp;quot;password&amp;quot;: &amp;quot;CHANGE_THIS_TO_A_STRONG_PASSWORD&amp;quot;,
      &amp;quot;tls&amp;quot;: {
        &amp;quot;enabled&amp;quot;: true,
        &amp;quot;server_name&amp;quot;: &amp;quot;YOUR_DOMAIN&amp;quot;
      }
    }
  ]
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;&lt;code&gt;hop_interval&lt;/code&gt; 默认 30s；1.14+ 可用 &lt;code&gt;hop_interval_max&lt;/code&gt; 做随机间隔。&lt;/p&gt;
&lt;h3 id=&quot;4-删除转发规则&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#4-删除转发规则&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;4. 删除转发规则&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;停用端口跳跃前删除对应规则：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-15&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-15&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo iptables -t nat -D PREROUTING -i eth0 -p udp --dport 20000:40000 -j DNAT --to-destination :9443
sudo ip6tables -t nat -D PREROUTING -i eth0 -p udp --dport 20000:40000 -j DNAT --to-destination :9443
sudo netfilter-persistent save&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;九-故障排查&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#九-故障排查&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;九、故障排查&lt;/span&gt;&lt;/h2&gt;
&lt;h3 id=&quot;1-服务启动失败&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#1-服务启动失败&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;1. 服务启动失败&lt;/span&gt;&lt;/h3&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-16&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-16&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo sing-box check -c /etc/sing-box/config.json
sudo journalctl -u sing-box -n 100 --no-pager&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;重点排查：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;sing-box version&lt;/code&gt; 是否 ≥ 1.14.0；&lt;/li&gt;
&lt;li&gt;证书路径是否正确，密钥文件权限是否可读；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;data_directory&lt;/code&gt; 是否可被 &lt;code&gt;sing-box&lt;/code&gt; 用户写入；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;up_mbps&lt;/code&gt; / &lt;code&gt;down_mbps&lt;/code&gt; 是否与 &lt;code&gt;ignore_client_bandwidth&lt;/code&gt; 同时设置；&lt;/li&gt;
&lt;li&gt;UDP 端口是否被占用（&lt;code&gt;sudo ss -lunp | grep -E ':443|:9443'&lt;/code&gt;）；&lt;/li&gt;
&lt;li&gt;禁用 IPv6 的机器是否仍在听 &lt;code&gt;::&lt;/code&gt;。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;2-服务启动但客户端无法连接&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#2-服务启动但客户端无法连接&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;2. 服务启动但客户端无法连接&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;依次检查：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;服务端口是否按 &lt;strong&gt;UDP&lt;/strong&gt; 放行（只放行 TCP 不够）；&lt;/li&gt;
&lt;li&gt;云安全组是否放行对应 UDP 端口；&lt;/li&gt;
&lt;li&gt;客户端密码是否完全一致；&lt;/li&gt;
&lt;li&gt;自签名证书是否已导入、&lt;code&gt;server_name&lt;/code&gt; 是否与证书中的伪装域名一致；不要靠长期 &lt;code&gt;insecure&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;服务端是否误用了 Ed25519 证书；&lt;/li&gt;
&lt;li&gt;服务端日志是否有认证失败或 QUIC 错误。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;3-端口跳跃不生效&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#3-端口跳跃不生效&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;3. 端口跳跃不生效&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;重点检查：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;服务端是否监听 &lt;code&gt;9443&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;客户端是否用了 &lt;code&gt;server_ports&lt;/code&gt; 且&lt;strong&gt;没有&lt;/strong&gt;同时写 &lt;code&gt;server_port&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;DNAT 规则是否使用 UDP、网卡是否为公网接口；&lt;/li&gt;
&lt;li&gt;防火墙是否放行整个跳跃端口范围（UDP 20000–40000）；&lt;/li&gt;
&lt;li&gt;IPv4 和 IPv6 是否分别添加了规则。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;查看 NAT 规则：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-17&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-17&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo iptables -t nat -L PREROUTING -n -v
sudo ip6tables -t nat -L PREROUTING -n -v&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h3 id=&quot;4-带宽参数怎么填写&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#4-带宽参数怎么填写&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;4. 带宽参数怎么填写&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;up_mbps&lt;/code&gt; 和 &lt;code&gt;down_mbps&lt;/code&gt; 应接近 VPS 实际带宽，填写过大可能导致拥塞、丢包或速度不稳。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;服务端不想限速：删除这两个字段（不限速，不是「强制 BBR」）；&lt;/li&gt;
&lt;li&gt;要客户端改用 BBR：在入站设 &lt;code&gt;&amp;quot;ignore_client_bandwidth&amp;quot;: true&lt;/code&gt;（此时不要同时写带宽字段）；&lt;/li&gt;
&lt;li&gt;客户端自己的 &lt;code&gt;up_mbps&lt;/code&gt; / &lt;code&gt;down_mbps&lt;/code&gt; 留空，该客户端使用 BBR。&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;十-安全建议&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#十-安全建议&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;十、安全建议&lt;/span&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;密码用长随机值，不要示例字符串；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;config.json&lt;/code&gt; 与 &lt;code&gt;server.key&lt;/code&gt; 权限 &lt;code&gt;600&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;优先 ACME 公网证书；自签要导入证书，不要长期开 &lt;code&gt;insecure&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;自签 / 手写证书用 P-256 或 RSA，不要 Ed25519；&lt;/li&gt;
&lt;li&gt;定期升级 sing-box，升级后重新执行 &lt;code&gt;sing-box check&lt;/code&gt;。&lt;/li&gt;
&lt;/ul&gt;
</description>
</item>
<item>
<title>Shadowsocks 部署指南（sing-box）</title>
<link>https://blog.fexumo.org/post/shadowsocks-deploy</link>
<guid isPermaLink="true">https://blog.fexumo.org/post/shadowsocks-deploy</guid>
<pubDate>Fri, 11 Sep 2026 00:00:00 GMT</pubDate>
<description>&lt;blockquote&gt;
&lt;p&gt;Shadowsocks 2022 版（&lt;code&gt;2022-blake3-*&lt;/code&gt;）修复了旧版协议的重放攻击漏洞，建议只使用 2022 系列加密方法。协议自带加密，无 TLS 层，无需证书。需要 &lt;strong&gt;sing-box 1.14.0 及以上&lt;/strong&gt;（与本系列其他篇一致；2022 方法本身更早可用）。字段说明见 &lt;a href=&quot;https://sing-box.sagernet.org/configuration/inbound/shadowsocks/&quot;&gt;Shadowsocks inbound&lt;/a&gt;。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;一-部署前准备&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#一-部署前准备&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;一、部署前准备&lt;/span&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;一台使用 systemd 的 Linux VPS，具备 root 或 &lt;code&gt;sudo&lt;/code&gt; 权限；官方安装脚本覆盖 &lt;strong&gt;deb / rpm / Arch / OpenWrt&lt;/strong&gt;；&lt;/li&gt;
&lt;li&gt;云安全组和本机防火墙都放行 TCP &lt;code&gt;443&lt;/code&gt;，且未被其他程序占用；服务端默认同时监听 TCP 和 UDP，需要 UDP 转发时一并放行——只改安全组不够；&lt;/li&gt;
&lt;li&gt;一个符合加密方法要求的密钥（见第三章）。&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;二-安装-sing-box&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#二-安装-sing-box&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;二、安装 sing-box&lt;/span&gt;&lt;/h2&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-1&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-1&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;curl -fsSL https://sing-box.app/install.sh | sh
sing-box version&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;输出中的版本号必须 ≥ 1.14.0。若要钉死版本：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-2&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-2&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;curl -fsSL https://sing-box.app/install.sh | sh -s -- --version 1.14.0&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;脚本会下载 sing-box、安装 systemd 服务（以 &lt;code&gt;sing-box&lt;/code&gt; 用户运行）并创建 &lt;code&gt;/etc/sing-box/&lt;/code&gt;。&lt;/p&gt;
&lt;h2 id=&quot;三-选择加密方法并生成密钥&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#三-选择加密方法并生成密钥&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;三、选择加密方法并生成密钥&lt;/span&gt;&lt;/h2&gt;
&lt;h3 id=&quot;1-加密方法选择&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#1-加密方法选择&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;1. 加密方法选择&lt;/span&gt;&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;加密方法&lt;/th&gt;
&lt;th&gt;密钥长度&lt;/th&gt;
&lt;th&gt;说明&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;2022-blake3-aes-128-gcm&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;16 字节&lt;/td&gt;
&lt;td&gt;AES-128，主流选择，CPU 支持 AES 加速时性能最好&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;2022-blake3-aes-256-gcm&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;32 字节&lt;/td&gt;
&lt;td&gt;AES-256，安全性余量更大&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;2022-blake3-chacha20-poly1305&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;32 字节&lt;/td&gt;
&lt;td&gt;无 AES 硬件加速的设备（部分 ARM）上性能更好；不支持多用户（EIH）&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&quot;2-生成密钥&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#2-生成密钥&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;2. 生成密钥&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;2022 系列要求密钥为恰好对应长度的 Base64 字符串，直接用 sing-box 生成：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-3&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-3&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;# 16 字节（对应 aes-128-gcm）
sing-box generate rand --base64 16

# 32 字节（对应 aes-256-gcm 或 chacha20-poly1305）
sing-box generate rand --base64 32&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;也可以用 OpenSSL 生成：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-4&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-4&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;openssl rand -base64 16&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;blockquote&gt;
&lt;p&gt;密钥必须与客户端完全一致，且长度必须精确匹配所选加密方法，否则服务端无法启动或连接失败。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;四-写入服务端配置&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#四-写入服务端配置&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;四、写入服务端配置&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;将以下配置写入 &lt;code&gt;/etc/sing-box/config.json&lt;/code&gt;：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-5&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-5&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;{
  &amp;quot;log&amp;quot;: {
    &amp;quot;level&amp;quot;: &amp;quot;info&amp;quot;,
    &amp;quot;timestamp&amp;quot;: true
  },
  &amp;quot;inbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;shadowsocks&amp;quot;,
      &amp;quot;listen&amp;quot;: &amp;quot;::&amp;quot;,
      &amp;quot;listen_port&amp;quot;: 443,
      &amp;quot;method&amp;quot;: &amp;quot;2022-blake3-aes-128-gcm&amp;quot;,
      &amp;quot;password&amp;quot;: &amp;quot;CHANGE_THIS_TO_GENERATED_KEY&amp;quot;
    }
  ],
  &amp;quot;outbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;direct&amp;quot;
    }
  ]
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h3 id=&quot;必须修改的字段&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#必须修改的字段&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;必须修改的字段&lt;/span&gt;&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;配置项&lt;/th&gt;
&lt;th&gt;说明&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;password&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;替换为生成的密钥，长度必须匹配加密方法&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;method&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;与客户端一致的加密方法，默认示例为 &lt;code&gt;2022-blake3-aes-128-gcm&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;listen_port&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;服务端监听端口，默认 &lt;code&gt;443&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;listen&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;默认 &lt;code&gt;::&lt;/code&gt;（IPv6 + IPv4）。机器禁用 IPv6 时改为 &lt;code&gt;0.0.0.0&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&quot;可选字段说明&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#可选字段说明&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;可选字段说明&lt;/span&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;network&lt;/code&gt;：省略时同时监听 TCP 与 UDP，一般无需设置。只保留 TCP 时设为 &lt;code&gt;&amp;quot;tcp&amp;quot;&lt;/code&gt;，只保留 UDP 时设为 &lt;code&gt;&amp;quot;udp&amp;quot;&lt;/code&gt;。官方字段是二者之一，&lt;strong&gt;不要&lt;/strong&gt;写 &lt;code&gt;&amp;quot;tcp,udp&amp;quot;&lt;/code&gt;，也&lt;strong&gt;不要&lt;/strong&gt;写成数组 &lt;code&gt;[&amp;quot;tcp&amp;quot;, &amp;quot;udp&amp;quot;]&lt;/code&gt;——要双栈就删掉该字段；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;multiplex&lt;/code&gt;：多路复用；&lt;code&gt;padding: true&lt;/code&gt; 启用填充、增加流量特征随机性，两端需配置一致（示例见下）。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;可选-启用多路复用-示例&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#可选-启用多路复用-示例&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;可选：启用多路复用（示例）&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;服务端入站与客户端出站加入相同配置：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-6&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-6&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;&amp;quot;multiplex&amp;quot;: {
  &amp;quot;enabled&amp;quot;: true,
  &amp;quot;padding&amp;quot;: true
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;blockquote&gt;
&lt;p&gt;开启 &lt;code&gt;padding&lt;/code&gt; 后服务端会拒绝未填充的连接。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;设置配置文件权限（官方服务以 &lt;code&gt;sing-box&lt;/code&gt; 用户运行，&lt;code&gt;600&lt;/code&gt;、属主 root 即可）：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-7&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-7&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo chmod 600 /etc/sing-box/config.json&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;五-检查并启动&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#五-检查并启动&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;五、检查并启动&lt;/span&gt;&lt;/h2&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-8&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-8&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo sing-box check -c /etc/sing-box/config.json
sudo systemctl enable sing-box
sudo systemctl restart sing-box
sudo systemctl status sing-box --no-pager&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;&lt;code&gt;check&lt;/code&gt; 没有输出且退出码为 &lt;code&gt;0&lt;/code&gt; 表示配置通过。&lt;code&gt;status&lt;/code&gt; 应为 &lt;code&gt;active (running)&lt;/code&gt;；否则查看日志：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-9&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-9&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo journalctl -u sing-box --output cat -e&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;六-服务管理&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#六-服务管理&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;六、服务管理&lt;/span&gt;&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;操作&lt;/th&gt;
&lt;th&gt;命令&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;查看状态&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl status sing-box --no-pager&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;启动&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl start sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;停止&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl stop sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;重启&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl restart sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;禁用开机自启&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl disable sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;查看最近日志&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo journalctl -u sing-box --output cat -e&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;实时查看日志&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo journalctl -u sing-box --output cat -f&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;七-客户端配置参考&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#七-客户端配置参考&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;七、客户端配置参考&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;下面是一份&lt;strong&gt;可直接 &lt;code&gt;sing-box check&lt;/code&gt; 的最小客户端配置&lt;/strong&gt;：本地 &lt;code&gt;mixed&lt;/code&gt; 入站 + 一个出站。出站必须放在 &lt;code&gt;outbounds&lt;/code&gt; 数组里，不能把出站对象单独当成完整配置文件。&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-10&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-10&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;{
  &amp;quot;log&amp;quot;: {
    &amp;quot;level&amp;quot;: &amp;quot;info&amp;quot;,
    &amp;quot;timestamp&amp;quot;: true
  },
  &amp;quot;inbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;mixed&amp;quot;,
      &amp;quot;listen&amp;quot;: &amp;quot;127.0.0.1&amp;quot;,
      &amp;quot;listen_port&amp;quot;: 1080
    }
  ],
  &amp;quot;outbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;shadowsocks&amp;quot;,
      &amp;quot;tag&amp;quot;: &amp;quot;ss-out&amp;quot;,
      &amp;quot;server&amp;quot;: &amp;quot;YOUR_SERVER_IP&amp;quot;,
      &amp;quot;server_port&amp;quot;: 443,
      &amp;quot;method&amp;quot;: &amp;quot;2022-blake3-aes-128-gcm&amp;quot;,
      &amp;quot;password&amp;quot;: &amp;quot;CHANGE_THIS_TO_GENERATED_KEY&amp;quot;
    }
  ]
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;本机 SOCKS / HTTP 代理为 &lt;code&gt;127.0.0.1:1080&lt;/code&gt;。&lt;/p&gt;
&lt;p&gt;要点：&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;客户端字段&lt;/th&gt;
&lt;th&gt;说明&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;server&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;VPS 公网 IP&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;server_port&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;与服务端 &lt;code&gt;listen_port&lt;/code&gt; 一致&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;method&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;与服务端 &lt;code&gt;method&lt;/code&gt; 完全一致&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;password&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;与服务端 &lt;code&gt;password&lt;/code&gt; 完全一致&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;blockquote&gt;
&lt;p&gt;Shadowsocks &lt;strong&gt;无 TLS 层&lt;/strong&gt;，客户端不配置 &lt;code&gt;tls&lt;/code&gt; 段。开在 443 能过防火墙，但流量不像 HTTPS。客户端出站默认同时支持 TCP 与 UDP（&lt;code&gt;network&lt;/code&gt; 留空即两者）；若只走 TCP，设为 &lt;code&gt;&amp;quot;tcp&amp;quot;&lt;/code&gt;。UDP 能否实际使用由服务端 &lt;code&gt;network&lt;/code&gt; 与防火墙共同决定。启用服务端 &lt;code&gt;multiplex&lt;/code&gt; 时，客户端需配置一致的 &lt;code&gt;multiplex&lt;/code&gt; 段。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;八-多用户配置-可选&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#八-多用户配置-可选&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;八、多用户配置（可选）&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;单端口多用户使用 &lt;code&gt;users&lt;/code&gt; 数组：顶层 &lt;code&gt;password&lt;/code&gt; 是服务端密钥（必填，不要删除），&lt;code&gt;users&lt;/code&gt; 中为每个用户的独立密钥：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-11&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-11&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;{
  &amp;quot;inbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;shadowsocks&amp;quot;,
      &amp;quot;listen&amp;quot;: &amp;quot;::&amp;quot;,
      &amp;quot;listen_port&amp;quot;: 443,
      &amp;quot;method&amp;quot;: &amp;quot;2022-blake3-aes-128-gcm&amp;quot;,
      &amp;quot;password&amp;quot;: &amp;quot;SERVER_KEY&amp;quot;,
      &amp;quot;users&amp;quot;: [
        {
          &amp;quot;name&amp;quot;: &amp;quot;user1&amp;quot;,
          &amp;quot;password&amp;quot;: &amp;quot;USER1_KEY&amp;quot;
        },
        {
          &amp;quot;name&amp;quot;: &amp;quot;user2&amp;quot;,
          &amp;quot;password&amp;quot;: &amp;quot;USER2_KEY&amp;quot;
        }
      ]
    }
  ]
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;&lt;code&gt;name&lt;/code&gt; 仅用于日志标识，可以省略；顶层 &lt;code&gt;password&lt;/code&gt; 与每个 &lt;code&gt;users[].password&lt;/code&gt; 都按所选方法生成（如 &lt;code&gt;sing-box generate rand --base64 16&lt;/code&gt;）。&lt;/p&gt;
&lt;p&gt;对应用户的客户端出站 &lt;code&gt;password&lt;/code&gt; 需要把两段密钥用冒号拼起来——服务端密钥在前、用户密钥在后：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-12&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-12&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;&amp;quot;password&amp;quot;: &amp;quot;SERVER_KEY:USER_KEY&amp;quot;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;blockquote&gt;
&lt;p&gt;EIH 多用户仅支持 &lt;code&gt;2022-blake3-aes-128-gcm&lt;/code&gt; 与 &lt;code&gt;2022-blake3-aes-256-gcm&lt;/code&gt; 两种方法；&lt;code&gt;2022-blake3-chacha20-poly1305&lt;/code&gt; 不支持多用户。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;中转链场景（流量经另一台 Shadowsocks 服务器转发）需要链式拼接多层 iPSK（参考 SIP023 规范），配置较复杂，本文不展开；普通自用场景用上面的多用户即可。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;九-故障排查&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#九-故障排查&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;九、故障排查&lt;/span&gt;&lt;/h2&gt;
&lt;h3 id=&quot;1-服务启动失败&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#1-服务启动失败&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;1. 服务启动失败&lt;/span&gt;&lt;/h3&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-13&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-13&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo sing-box check -c /etc/sing-box/config.json
sudo journalctl -u sing-box -n 100 --no-pager&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;重点排查：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;password&lt;/code&gt; 长度是否与加密方法匹配（aes-128-gcm 对应 16 字节 Base64，其余对应 32 字节）；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;password&lt;/code&gt; 是否为合法 Base64 字符串；&lt;/li&gt;
&lt;li&gt;使用多用户时顶层 &lt;code&gt;password&lt;/code&gt;（服务端密钥）是否缺失——多用户模式下它仍是必填项；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;network&lt;/code&gt; 是否写成了 &lt;code&gt;&amp;quot;tcp,udp&amp;quot;&lt;/code&gt; 或数组；&lt;/li&gt;
&lt;li&gt;端口是否被占用（TCP 与 UDP 都看：&lt;code&gt;sudo ss -lntup | grep ':443'&lt;/code&gt;）；&lt;/li&gt;
&lt;li&gt;禁用 IPv6 的机器是否仍在听 &lt;code&gt;::&lt;/code&gt;（改为 &lt;code&gt;0.0.0.0&lt;/code&gt;）。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;2-客户端无法连接&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#2-客户端无法连接&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;2. 客户端无法连接&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;依次确认：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;systemctl status&lt;/code&gt; 为 &lt;code&gt;active (running)&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;云安全组和系统防火墙放行对应端口（服务端默认同时监听 TCP 与 UDP，需要 UDP 时记得放行）；&lt;/li&gt;
&lt;li&gt;客户端 &lt;code&gt;method&lt;/code&gt; 与服务端一致；单用户时 &lt;code&gt;password&lt;/code&gt; 与服务端完全一致，多用户时 &lt;code&gt;password&lt;/code&gt; 为 &lt;code&gt;服务端密钥:用户密钥&lt;/code&gt; 形式（顺序、冒号均不能错）；&lt;/li&gt;
&lt;li&gt;客户端密钥长度与服务端相同（两侧必须使用同一套密钥，不是各生成各的）；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;multiplex&lt;/code&gt; 两侧配置一致；&lt;/li&gt;
&lt;li&gt;服务端日志中没有认证失败或解密错误。&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;3-日志频繁出现认证失败&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#3-日志频繁出现认证失败&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;3. 日志频繁出现认证失败&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;少量失败通常来自互联网扫描，属正常现象。持续大量失败时检查：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;客户端密钥是否与 &lt;code&gt;password&lt;/code&gt; 完全一致（注意 Base64 大小写和结尾 &lt;code&gt;=&lt;/code&gt;）；&lt;/li&gt;
&lt;li&gt;密钥是否已泄露，泄露后立即更换。&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;十-安全建议&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#十-安全建议&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;十、安全建议&lt;/span&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;只使用 2022 系列加密方法；旧版（&lt;code&gt;aes-256-gcm&lt;/code&gt; 等非 2022 前缀）存在已知重放攻击风险；&lt;/li&gt;
&lt;li&gt;密钥用生成命令出，长度必须匹配加密方法；泄露后立即更换；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;config.json&lt;/code&gt; 权限 &lt;code&gt;600&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;443 上无 TLS，被主动探测时特征与 HTTPS 不同；&lt;/li&gt;
&lt;li&gt;定期升级 sing-box，升级后重新执行 &lt;code&gt;sing-box check&lt;/code&gt;。&lt;/li&gt;
&lt;/ul&gt;
</description>
</item>
<item>
<title>Snell v6 部署指南（sing-box）</title>
<link>https://blog.fexumo.org/post/snell-v6-deploy</link>
<guid isPermaLink="true">https://blog.fexumo.org/post/snell-v6-deploy</guid>
<pubDate>Fri, 11 Sep 2026 00:00:00 GMT</pubDate>
<description>&lt;blockquote&gt;
&lt;p&gt;Snell 为 sing-box 1.14.0 新增。请安装 &lt;strong&gt;1.14.0 及以上&lt;/strong&gt;，并在写入配置前用 &lt;code&gt;sing-box version&lt;/code&gt; 确认。字段说明见 &lt;a href=&quot;https://sing-box.sagernet.org/configuration/inbound/snell/&quot;&gt;Snell inbound&lt;/a&gt; 与 &lt;a href=&quot;https://sing-box.sagernet.org/configuration/outbound/snell/&quot;&gt;outbound&lt;/a&gt;。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;一-snell-v6-简介&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#一-snell-v6-简介&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;一、Snell v6 简介&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;Snell v6 使用预共享密钥（PSK）派生协议画像，并通过 &lt;code&gt;mode&lt;/code&gt; 控制流量整形方式。不同 PSK 会产生不同的部署特征，因此不要在多个服务之间重复使用同一个 PSK。&lt;/p&gt;
&lt;p&gt;常用模式：&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;模式&lt;/th&gt;
&lt;th&gt;说明&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;default&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;默认流量整形模式，适合生产环境&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;unshaped&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;不应用流量整形，回退到 v4 风格的随机数据流特征&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;unsafe-raw&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;明文调试模式，不提供加密能力，禁止用于生产环境&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;二-部署前准备&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#二-部署前准备&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;二、部署前准备&lt;/span&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;一台使用 systemd 的 Linux VPS，具备 root 或 &lt;code&gt;sudo&lt;/code&gt; 权限；官方安装脚本覆盖 &lt;strong&gt;deb / rpm / Arch / OpenWrt&lt;/strong&gt;，不是任意发行版；&lt;/li&gt;
&lt;li&gt;云安全组和本机防火墙（ufw / firewalld / nftables）都放行 TCP &lt;code&gt;443&lt;/code&gt;，且未被其他程序占用——只改安全组不够；&lt;/li&gt;
&lt;li&gt;准备一串长度为 12–255 字节的随机 PSK。&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;三-安装-sing-box&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#三-安装-sing-box&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;三、安装 sing-box&lt;/span&gt;&lt;/h2&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-1&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-1&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;curl -fsSL https://sing-box.app/install.sh | sh
sing-box version&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;输出中的版本号必须 ≥ 1.14.0，否则入站类型 &lt;code&gt;snell&lt;/code&gt; 无法识别。若要钉死版本：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-2&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-2&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;curl -fsSL https://sing-box.app/install.sh | sh -s -- --version 1.14.0&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;脚本会下载 sing-box、安装 systemd 服务（以 &lt;code&gt;sing-box&lt;/code&gt; 用户运行，配置目录 &lt;code&gt;/etc/sing-box/&lt;/code&gt;）。&lt;/p&gt;
&lt;h2 id=&quot;四-生成-psk&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#四-生成-psk&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;四、生成 PSK&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;PSK 的字符串长度必须在 12–255 字节之间。推荐用 sing-box 自带命令生成 32 字节随机值的 Base64 编码（44 个字符，稳定落在范围内）：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-3&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-3&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sing-box generate rand --base64 32&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;复制输出结果，稍后填入配置中的 &lt;code&gt;psk&lt;/code&gt;。也可以用 OpenSSL 生成同样长度的随机值：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-4&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-4&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;openssl rand -base64 32&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;blockquote&gt;
&lt;p&gt;长度按 Base64 文本本身计算：原始随机值不要超过 189 字节（Base64 后约 252 个字符），超出 255 字节上限会导致配置校验失败。不要使用短密码、可猜测字符串或多个服务器共用的 PSK。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;五-写入服务端配置&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#五-写入服务端配置&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;五、写入服务端配置&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;将以下配置写入 &lt;code&gt;/etc/sing-box/config.json&lt;/code&gt;：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-5&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-5&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;{
  &amp;quot;log&amp;quot;: {
    &amp;quot;level&amp;quot;: &amp;quot;info&amp;quot;,
    &amp;quot;timestamp&amp;quot;: true
  },
  &amp;quot;inbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;snell&amp;quot;,
      &amp;quot;listen&amp;quot;: &amp;quot;::&amp;quot;,
      &amp;quot;listen_port&amp;quot;: 443,
      &amp;quot;version&amp;quot;: 6,
      &amp;quot;psk&amp;quot;: &amp;quot;CHANGE_THIS_TO_A_GENERATED_PSK&amp;quot;
    }
  ],
  &amp;quot;outbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;direct&amp;quot;
    }
  ]
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h3 id=&quot;必须修改的字段&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#必须修改的字段&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;必须修改的字段&lt;/span&gt;&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;配置项&lt;/th&gt;
&lt;th&gt;说明&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;inbounds[0].psk&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;替换为刚刚生成的随机 PSK（长度 12–255 字节，按字符串本身计）&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;inbounds[0].listen_port&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;服务端监听端口，默认 &lt;code&gt;443&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;inbounds[0].listen&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;默认 &lt;code&gt;::&lt;/code&gt;（IPv6 + IPv4）。机器禁用 IPv6、启动报 &lt;code&gt;cannot assign requested address&lt;/code&gt; 时改为 &lt;code&gt;0.0.0.0&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;mode&lt;/code&gt; 默认为 &lt;code&gt;default&lt;/code&gt;（流量整形），推荐保持默认，仅在明确了解影响时修改。可选 &lt;code&gt;&amp;quot;reuse&amp;quot;: true&lt;/code&gt; 启用连接复用（Snell v2 &lt;code&gt;CONNECT&lt;/code&gt;），一般保持默认即可。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;设置配置文件权限（官方服务以 &lt;code&gt;sing-box&lt;/code&gt; 用户运行，&lt;code&gt;600&lt;/code&gt;、属主 root 即可）：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-6&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-6&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo chmod 600 /etc/sing-box/config.json&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;六-多用户配置-可选&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#六-多用户配置-可选&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;六、多用户配置（可选）&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;如果需要为不同用户设置独立密钥，可以使用 &lt;code&gt;users&lt;/code&gt;。顶层 &lt;code&gt;psk&lt;/code&gt; 作为服务器密钥，每个用户使用自己的 &lt;code&gt;userkey&lt;/code&gt;：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-7&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-7&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;{
  &amp;quot;inbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;snell&amp;quot;,
      &amp;quot;listen&amp;quot;: &amp;quot;::&amp;quot;,
      &amp;quot;listen_port&amp;quot;: 443,
      &amp;quot;version&amp;quot;: 6,
      &amp;quot;psk&amp;quot;: &amp;quot;SERVER_PSK&amp;quot;,
      &amp;quot;users&amp;quot;: [
        {
          &amp;quot;name&amp;quot;: &amp;quot;user1&amp;quot;,
          &amp;quot;userkey&amp;quot;: &amp;quot;USER1_KEY&amp;quot;
        },
        {
          &amp;quot;name&amp;quot;: &amp;quot;user2&amp;quot;,
          &amp;quot;userkey&amp;quot;: &amp;quot;USER2_KEY&amp;quot;
        }
      ]
    }
  ],
  &amp;quot;outbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;direct&amp;quot;
    }
  ]
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;&lt;code&gt;name&lt;/code&gt; 仅用于日志标识，可以省略；&lt;code&gt;userkey&lt;/code&gt; 用于对应用户认证。&lt;/p&gt;
&lt;p&gt;对应用户的客户端出站需要同时填写服务端顶层 &lt;code&gt;psk&lt;/code&gt; 和该用户的 &lt;code&gt;userkey&lt;/code&gt;：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-8&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-8&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;&amp;quot;psk&amp;quot;: &amp;quot;SERVER_PSK&amp;quot;,
&amp;quot;userkey&amp;quot;: &amp;quot;USER1_KEY&amp;quot;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;七-检查并启动&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#七-检查并启动&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;七、检查并启动&lt;/span&gt;&lt;/h2&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-9&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-9&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo sing-box check -c /etc/sing-box/config.json
sudo systemctl enable sing-box
sudo systemctl restart sing-box
sudo systemctl status sing-box --no-pager&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;&lt;code&gt;check&lt;/code&gt; 没有输出且退出码为 &lt;code&gt;0&lt;/code&gt; 表示配置通过。&lt;code&gt;status&lt;/code&gt; 应为 &lt;code&gt;active (running)&lt;/code&gt;；否则查看日志：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-10&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-10&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo journalctl -u sing-box --output cat -e&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;八-服务管理&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#八-服务管理&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;八、服务管理&lt;/span&gt;&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;操作&lt;/th&gt;
&lt;th&gt;命令&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;查看状态&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl status sing-box --no-pager&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;启动&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl start sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;停止&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl stop sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;重启&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl restart sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;禁用开机自启&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl disable sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;查看最近日志&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo journalctl -u sing-box --output cat -e&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;实时查看日志&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo journalctl -u sing-box --output cat -f&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;九-客户端配置参考&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#九-客户端配置参考&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;九、客户端配置参考&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;下面是一份&lt;strong&gt;可直接 &lt;code&gt;sing-box check&lt;/code&gt; 的最小客户端配置&lt;/strong&gt;：本地 &lt;code&gt;mixed&lt;/code&gt; 入站 + 一个出站。出站必须放在 &lt;code&gt;outbounds&lt;/code&gt; 数组里，不能把出站对象单独当成完整配置文件。&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-11&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-11&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;{
  &amp;quot;log&amp;quot;: {
    &amp;quot;level&amp;quot;: &amp;quot;info&amp;quot;,
    &amp;quot;timestamp&amp;quot;: true
  },
  &amp;quot;inbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;mixed&amp;quot;,
      &amp;quot;listen&amp;quot;: &amp;quot;127.0.0.1&amp;quot;,
      &amp;quot;listen_port&amp;quot;: 1080
    }
  ],
  &amp;quot;outbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;snell&amp;quot;,
      &amp;quot;tag&amp;quot;: &amp;quot;snell-out&amp;quot;,
      &amp;quot;server&amp;quot;: &amp;quot;YOUR_SERVER_IP&amp;quot;,
      &amp;quot;server_port&amp;quot;: 443,
      &amp;quot;psk&amp;quot;: &amp;quot;CHANGE_THIS_TO_A_GENERATED_PSK&amp;quot;,
      &amp;quot;version&amp;quot;: 6
    }
  ]
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;本机 SOCKS / HTTP 代理为 &lt;code&gt;127.0.0.1:1080&lt;/code&gt;。&lt;/p&gt;
&lt;p&gt;要点：&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;客户端字段&lt;/th&gt;
&lt;th&gt;说明&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;server&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;VPS 公网 IP&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;server_port&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;与服务端 &lt;code&gt;listen_port&lt;/code&gt; 一致&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;psk&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;始终填服务端顶层 &lt;code&gt;psk&lt;/code&gt;；服务端启用多用户时，还需填写属于该用户的 &lt;code&gt;userkey&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;version&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;与服务端 &lt;code&gt;version&lt;/code&gt; 一致，Snell v6 为 &lt;code&gt;6&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;blockquote&gt;
&lt;p&gt;Snell 协议自带加密，&lt;strong&gt;没有 TLS 层&lt;/strong&gt;。把服务开在 443 能过防火墙，但流量不像 HTTPS，按需换端口或接受可探测性。v6 的 &lt;code&gt;mode&lt;/code&gt; 需要两端一致：客户端默认为 &lt;code&gt;default&lt;/code&gt;，与服务端默认相同；服务端改用 &lt;code&gt;unshaped&lt;/code&gt; 时客户端也要同步修改（&lt;code&gt;unsafe-raw&lt;/code&gt; 仅供调试）。客户端同样需要 sing-box 1.14.0+。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;十-故障排查&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#十-故障排查&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;十、故障排查&lt;/span&gt;&lt;/h2&gt;
&lt;h3 id=&quot;1-服务启动失败&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#1-服务启动失败&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;1. 服务启动失败&lt;/span&gt;&lt;/h3&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-12&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-12&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo sing-box check -c /etc/sing-box/config.json
sudo journalctl -u sing-box -n 100 --no-pager&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;重点排查：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;sing-box version&lt;/code&gt; 是否 ≥ 1.14.0；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;version&lt;/code&gt; 是否写为数字 &lt;code&gt;6&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;PSK 是否为空或长度不在 12–255 字节范围内；&lt;/li&gt;
&lt;li&gt;443 端口是否被其他程序占用（&lt;code&gt;sudo ss -lntp | grep ':443'&lt;/code&gt;）；&lt;/li&gt;
&lt;li&gt;禁用 IPv6 的机器是否仍在听 &lt;code&gt;::&lt;/code&gt;（改为 &lt;code&gt;0.0.0.0&lt;/code&gt;）。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;2-客户端无法连接&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#2-客户端无法连接&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;2. 客户端无法连接&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;依次确认：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;systemctl status&lt;/code&gt; 为 &lt;code&gt;active (running)&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;客户端地址、端口和 PSK 完全一致；&lt;/li&gt;
&lt;li&gt;云安全组和系统防火墙放行 TCP 443；&lt;/li&gt;
&lt;li&gt;两端 &lt;code&gt;mode&lt;/code&gt; 是否一致（默认均为 &lt;code&gt;default&lt;/code&gt;）；&lt;/li&gt;
&lt;li&gt;多用户时客户端填对应 &lt;code&gt;userkey&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;服务端日志中没有认证失败或协议版本错误。&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;3-是否应该使用-unsafe-raw&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#3-是否应该使用-unsafe-raw&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;3. 是否应该使用 &lt;code&gt;unsafe-raw&lt;/code&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;不应该。&lt;code&gt;unsafe-raw&lt;/code&gt; 仅适合本地调试、流量不加密；生产环境应使用 &lt;code&gt;default&lt;/code&gt;，或在了解兼容性影响后使用 &lt;code&gt;unshaped&lt;/code&gt;。&lt;/p&gt;
&lt;h3 id=&quot;4-如何确认版本兼容性&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#4-如何确认版本兼容性&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;4. 如何确认版本兼容性&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;出现 &lt;code&gt;unknown inbound type&lt;/code&gt;、&lt;code&gt;unsupported version&lt;/code&gt; 等错误时，说明当前版本不支持 Snell v6，升级到 1.14.0+ 后重试。&lt;/p&gt;
&lt;h2 id=&quot;十一-安全建议&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#十一-安全建议&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;十一、安全建议&lt;/span&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;PSK 用生成命令出，长度落在 12–255 字节，不要短口令、不要多机复用；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;config.json&lt;/code&gt; 权限 &lt;code&gt;600&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;不要在生产环境使用 &lt;code&gt;unsafe-raw&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;443 上无 TLS，被主动探测时特征与 HTTPS 不同；&lt;/li&gt;
&lt;li&gt;定期升级 sing-box，升级后重新执行 &lt;code&gt;sing-box check&lt;/code&gt;。&lt;/li&gt;
&lt;/ul&gt;
</description>
</item>
<item>
<title>VLESS 部署指南（sing-box）</title>
<link>https://blog.fexumo.org/post/vless-deploy</link>
<guid isPermaLink="true">https://blog.fexumo.org/post/vless-deploy</guid>
<pubDate>Fri, 11 Sep 2026 00:00:00 GMT</pubDate>
<description>&lt;p&gt;采用 VLESS + Reality + &lt;code&gt;xtls-rprx-vision&lt;/code&gt; 方案：无需域名和证书，伪装为正常 HTTPS 流量。需要 &lt;strong&gt;sing-box 1.14.0 及以上&lt;/strong&gt;（与本系列其他篇一致；Reality 本身更早可用）。字段说明见 &lt;a href=&quot;https://sing-box.sagernet.org/configuration/inbound/vless/&quot;&gt;VLESS inbound&lt;/a&gt; 与 &lt;a href=&quot;https://sing-box.sagernet.org/configuration/shared/tls/&quot;&gt;TLS / Reality&lt;/a&gt;。&lt;/p&gt;
&lt;h2 id=&quot;一-部署前准备&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#一-部署前准备&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;一、部署前准备&lt;/span&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;一台使用 systemd 的 Linux VPS，具备 root 或 &lt;code&gt;sudo&lt;/code&gt; 权限；官方安装脚本覆盖 &lt;strong&gt;deb / rpm / Arch / OpenWrt&lt;/strong&gt;；&lt;/li&gt;
&lt;li&gt;云安全组和本机防火墙放行 TCP &lt;code&gt;443&lt;/code&gt;，且未被其他程序占用——只改安全组不够；&lt;/li&gt;
&lt;li&gt;出站方向可正常访问 443 端口（Reality 握手需要转发到目标站点）。&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;二-安装-sing-box&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#二-安装-sing-box&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;二、安装 sing-box&lt;/span&gt;&lt;/h2&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-1&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-1&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;curl -fsSL https://sing-box.app/install.sh | sh
sing-box version&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;输出中的版本号必须 ≥ 1.14.0。若要钉死版本：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-2&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-2&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;curl -fsSL https://sing-box.app/install.sh | sh -s -- --version 1.14.0&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;脚本会下载 sing-box、安装 systemd 服务（以 &lt;code&gt;sing-box&lt;/code&gt; 用户运行）并创建 &lt;code&gt;/etc/sing-box/&lt;/code&gt;。&lt;/p&gt;
&lt;h2 id=&quot;三-生成密钥和用户标识&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#三-生成密钥和用户标识&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;三、生成密钥和用户标识&lt;/span&gt;&lt;/h2&gt;
&lt;h3 id=&quot;1-生成-reality-密钥对&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#1-生成-reality-密钥对&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;1. 生成 Reality 密钥对&lt;/span&gt;&lt;/h3&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-3&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-3&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sing-box generate reality-keypair&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;输出示例：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-4&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-4&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;text&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;PrivateKey: YOUR_PRIVATE_KEY
PublicKey:  YOUR_PUBLIC_KEY&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;PrivateKey&lt;/code&gt; 填入服务端配置；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;PublicKey&lt;/code&gt; 填入客户端配置。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;2-生成用户-uuid&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#2-生成用户-uuid&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;2. 生成用户 UUID&lt;/span&gt;&lt;/h3&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-5&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-5&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sing-box generate uuid&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;不要手编「好记」的 UUID。&lt;/p&gt;
&lt;h3 id=&quot;3-生成-short-id&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#3-生成-short-id&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;3. 生成 short_id&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;short_id 是十六进制字符串，解码后不能超过 8 字节（即最多 16 个十六进制字符，长度必须为偶数）。一般用 OpenSSL 生成 4 字节（8 个字符）：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-6&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-6&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;openssl rand -hex 4&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;超过 16 个十六进制字符会导致&lt;strong&gt;配置校验失败&lt;/strong&gt;。把三项输出记录好，下一步分别填入服务端和客户端配置。&lt;/p&gt;
&lt;h2 id=&quot;四-写入服务端配置&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#四-写入服务端配置&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;四、写入服务端配置&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;将以下配置写入 &lt;code&gt;/etc/sing-box/config.json&lt;/code&gt;：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-7&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-7&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;{
  &amp;quot;log&amp;quot;: {
    &amp;quot;level&amp;quot;: &amp;quot;info&amp;quot;,
    &amp;quot;timestamp&amp;quot;: true
  },
  &amp;quot;inbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;vless&amp;quot;,
      &amp;quot;listen&amp;quot;: &amp;quot;::&amp;quot;,
      &amp;quot;listen_port&amp;quot;: 443,
      &amp;quot;users&amp;quot;: [
        {
          &amp;quot;uuid&amp;quot;: &amp;quot;CHANGE_THIS_TO_GENERATED_UUID&amp;quot;,
          &amp;quot;flow&amp;quot;: &amp;quot;xtls-rprx-vision&amp;quot;
        }
      ],
      &amp;quot;tls&amp;quot;: {
        &amp;quot;enabled&amp;quot;: true,
        &amp;quot;server_name&amp;quot;: &amp;quot;www.microsoft.com&amp;quot;,
        &amp;quot;reality&amp;quot;: {
          &amp;quot;enabled&amp;quot;: true,
          &amp;quot;handshake&amp;quot;: {
            &amp;quot;server&amp;quot;: &amp;quot;www.microsoft.com&amp;quot;,
            &amp;quot;server_port&amp;quot;: 443
          },
          &amp;quot;private_key&amp;quot;: &amp;quot;CHANGE_THIS_TO_PRIVATE_KEY&amp;quot;,
          &amp;quot;short_id&amp;quot;: [
            &amp;quot;CHANGE_THIS_TO_SHORT_ID&amp;quot;
          ]
        }
      }
    }
  ],
  &amp;quot;outbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;direct&amp;quot;
    }
  ]
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;使用 &lt;code&gt;xtls-rprx-vision&lt;/code&gt; 时&lt;strong&gt;不要&lt;/strong&gt;启用 &lt;code&gt;multiplex&lt;/code&gt;。&lt;/p&gt;
&lt;h3 id=&quot;必须修改的字段&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#必须修改的字段&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;必须修改的字段&lt;/span&gt;&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;配置项&lt;/th&gt;
&lt;th&gt;填入内容&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;users[0].uuid&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sing-box generate uuid&lt;/code&gt; 的输出&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tls.reality.private_key&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sing-box generate reality-keypair&lt;/code&gt; 输出的 &lt;code&gt;PrivateKey&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tls.reality.short_id&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;openssl rand -hex 4&lt;/code&gt; 的输出（偶数长度，最多 16 个十六进制字符）&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tls.server_name&lt;/code&gt; / &lt;code&gt;tls.reality.handshake.server&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;用于伪装的目标站点域名&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;listen&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;默认 &lt;code&gt;::&lt;/code&gt;。机器禁用 IPv6 时改为 &lt;code&gt;0.0.0.0&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;设置配置文件权限（官方服务以 &lt;code&gt;sing-box&lt;/code&gt; 用户运行，&lt;code&gt;600&lt;/code&gt;、属主 root 即可）：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-8&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-8&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo chmod 600 /etc/sing-box/config.json&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h3 id=&quot;伪装站点怎么选&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#伪装站点怎么选&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;伪装站点怎么选&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;server_name&lt;/code&gt; 和 &lt;code&gt;handshake.server&lt;/code&gt; 决定 Reality 借用哪个真实站点完成握手：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;选国外大型、支持 TLS 1.3 和 HTTP/2 的 HTTPS 站点，最好与 VPS 地区较近；&lt;/li&gt;
&lt;li&gt;不要使用自己控制或容易关停的站点；&lt;/li&gt;
&lt;li&gt;常见选择：&lt;code&gt;www.microsoft.com&lt;/code&gt;、&lt;code&gt;www.samsung.com&lt;/code&gt;、&lt;code&gt;www.lovelive-anime.jp&lt;/code&gt; 等；&lt;/li&gt;
&lt;li&gt;VPS 必须能出站访问该站点，选完先在 VPS 上 &lt;code&gt;curl -I&lt;/code&gt; 验证。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;server_name&lt;/code&gt;、&lt;code&gt;handshake.server&lt;/code&gt; 与客户端的 &lt;code&gt;server_name&lt;/code&gt; 必须完全一致。&lt;/p&gt;
&lt;h2 id=&quot;五-检查并启动&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#五-检查并启动&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;五、检查并启动&lt;/span&gt;&lt;/h2&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-9&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-9&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo sing-box check -c /etc/sing-box/config.json
sudo systemctl enable sing-box
sudo systemctl restart sing-box
sudo systemctl status sing-box --no-pager&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;&lt;code&gt;check&lt;/code&gt; 没有输出且退出码为 &lt;code&gt;0&lt;/code&gt; 表示配置通过。&lt;code&gt;status&lt;/code&gt; 应为 &lt;code&gt;active (running)&lt;/code&gt;；否则查看日志：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-10&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-10&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo journalctl -u sing-box --output cat -e&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;六-服务管理&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#六-服务管理&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;六、服务管理&lt;/span&gt;&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;操作&lt;/th&gt;
&lt;th&gt;命令&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;查看状态&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl status sing-box --no-pager&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;启动&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl start sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;停止&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl stop sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;重启&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl restart sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;禁用开机自启&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo systemctl disable sing-box&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;查看最近日志&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo journalctl -u sing-box --output cat -e&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;实时查看日志&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sudo journalctl -u sing-box --output cat -f&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;七-客户端配置参考&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#七-客户端配置参考&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;七、客户端配置参考&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;下面是一份&lt;strong&gt;可直接 &lt;code&gt;sing-box check&lt;/code&gt; 的最小客户端配置&lt;/strong&gt;：本地 &lt;code&gt;mixed&lt;/code&gt; 入站 + 一个出站。出站必须放在 &lt;code&gt;outbounds&lt;/code&gt; 数组里，不能把出站对象单独当成完整配置文件。&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-11&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-11&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;{
  &amp;quot;log&amp;quot;: {
    &amp;quot;level&amp;quot;: &amp;quot;info&amp;quot;,
    &amp;quot;timestamp&amp;quot;: true
  },
  &amp;quot;inbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;mixed&amp;quot;,
      &amp;quot;listen&amp;quot;: &amp;quot;127.0.0.1&amp;quot;,
      &amp;quot;listen_port&amp;quot;: 1080
    }
  ],
  &amp;quot;outbounds&amp;quot;: [
    {
      &amp;quot;type&amp;quot;: &amp;quot;vless&amp;quot;,
      &amp;quot;tag&amp;quot;: &amp;quot;vless-out&amp;quot;,
      &amp;quot;server&amp;quot;: &amp;quot;YOUR_SERVER_IP&amp;quot;,
      &amp;quot;server_port&amp;quot;: 443,
      &amp;quot;uuid&amp;quot;: &amp;quot;CHANGE_THIS_TO_GENERATED_UUID&amp;quot;,
      &amp;quot;flow&amp;quot;: &amp;quot;xtls-rprx-vision&amp;quot;,
      &amp;quot;tls&amp;quot;: {
        &amp;quot;enabled&amp;quot;: true,
        &amp;quot;server_name&amp;quot;: &amp;quot;www.microsoft.com&amp;quot;,
        &amp;quot;utls&amp;quot;: {
          &amp;quot;enabled&amp;quot;: true,
          &amp;quot;fingerprint&amp;quot;: &amp;quot;chrome&amp;quot;
        },
        &amp;quot;reality&amp;quot;: {
          &amp;quot;enabled&amp;quot;: true,
          &amp;quot;public_key&amp;quot;: &amp;quot;CHANGE_THIS_TO_PUBLIC_KEY&amp;quot;,
          &amp;quot;short_id&amp;quot;: &amp;quot;CHANGE_THIS_TO_SHORT_ID&amp;quot;
        }
      }
    }
  ]
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;本机 SOCKS / HTTP 代理为 &lt;code&gt;127.0.0.1:1080&lt;/code&gt;。&lt;/p&gt;
&lt;p&gt;要点：&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;客户端字段&lt;/th&gt;
&lt;th&gt;说明&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;server&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;VPS 公网 IP&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;uuid&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;与服务端 &lt;code&gt;users[0].uuid&lt;/code&gt; 一致&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;flow&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;必须同为 &lt;code&gt;xtls-rprx-vision&lt;/code&gt;，两端不能只有一端启用&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tls.server_name&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;与服务端 &lt;code&gt;server_name&lt;/code&gt; 一致&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tls.reality.public_key&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;服务端密钥对中的 &lt;code&gt;PublicKey&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tls.reality.short_id&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;服务端 &lt;code&gt;short_id&lt;/code&gt; 列表中的其中一项（客户端是字符串，服务端是数组）&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;utls.fingerprint&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;模拟的浏览器 TLS 指纹，常用 &lt;code&gt;chrome&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;八-故障排查&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#八-故障排查&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;八、故障排查&lt;/span&gt;&lt;/h2&gt;
&lt;h3 id=&quot;1-服务启动失败&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#1-服务启动失败&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;1. 服务启动失败&lt;/span&gt;&lt;/h3&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-12&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-12&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;sudo sing-box check -c /etc/sing-box/config.json
sudo journalctl -u sing-box -n 100 --no-pager&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;重点排查：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;private_key&lt;/code&gt; 是否完整复制，注意结尾不要带引号或空格；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;short_id&lt;/code&gt; 是否为偶数长度、且解码后不超过 8 字节的十六进制字符串（超过 16 个字符会校验失败）；&lt;/li&gt;
&lt;li&gt;443 端口是否被其他程序占用（&lt;code&gt;sudo ss -lntp | grep ':443'&lt;/code&gt;）；&lt;/li&gt;
&lt;li&gt;UUID 是否为有效格式；&lt;/li&gt;
&lt;li&gt;是否在 Vision 下误开了 &lt;code&gt;multiplex&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;禁用 IPv6 的机器是否仍在听 &lt;code&gt;::&lt;/code&gt;（改为 &lt;code&gt;0.0.0.0&lt;/code&gt;）。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;2-客户端无法连接&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#2-客户端无法连接&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;2. 客户端无法连接&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;依次确认：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;systemctl status&lt;/code&gt; 为 &lt;code&gt;active (running)&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;云安全组和系统防火墙放行 TCP 443；&lt;/li&gt;
&lt;li&gt;客户端 &lt;code&gt;uuid&lt;/code&gt;、&lt;code&gt;flow&lt;/code&gt;、&lt;code&gt;server_name&lt;/code&gt;、&lt;code&gt;public_key&lt;/code&gt;、&lt;code&gt;short_id&lt;/code&gt; 与服务端完全一致；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;flow&lt;/code&gt; 两端一致：要么都启用，要么都不启用；&lt;/li&gt;
&lt;li&gt;客户端与服务端系统时间相差过大也会导致握手失败。可用 &lt;code&gt;tls.reality.max_time_difference&lt;/code&gt; 放宽容差（官方示例为 &lt;code&gt;1m&lt;/code&gt;，省略时的默认值以当前版本文档为准）；&lt;/li&gt;
&lt;li&gt;VPS 能正常出站访问伪装站点：&lt;/li&gt;
&lt;/ol&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-13&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-13&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;curl -I --max-time 10 https://www.microsoft.com&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;如果出站被墙或被拦截，更换 &lt;code&gt;handshake.server&lt;/code&gt; 为可访问的站点。&lt;/p&gt;
&lt;h3 id=&quot;3-可以同时启用多用户吗&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#3-可以同时启用多用户吗&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;3. 可以同时启用多用户吗&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;可以。在 &lt;code&gt;users&lt;/code&gt; 数组中添加多个用户，每个用户使用独立 UUID：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-14&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-14&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;json&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;&amp;quot;users&amp;quot;: [
  {
    &amp;quot;uuid&amp;quot;: &amp;quot;USER1_UUID&amp;quot;,
    &amp;quot;flow&amp;quot;: &amp;quot;xtls-rprx-vision&amp;quot;
  },
  {
    &amp;quot;uuid&amp;quot;: &amp;quot;USER2_UUID&amp;quot;,
    &amp;quot;flow&amp;quot;: &amp;quot;xtls-rprx-vision&amp;quot;
  }
]&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;所有用户共用同一组 Reality 密钥和 &lt;code&gt;short_id&lt;/code&gt;，修改配置后重启服务生效。&lt;/p&gt;
&lt;h3 id=&quot;4-为什么没有证书申请环节&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#4-为什么没有证书申请环节&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;4. 为什么没有证书申请环节&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;Reality 模式下证书由伪装目标站点的握手链路提供，服务端只保管自己的密钥对，因此无需域名、无需 ACME——既省去证书续期，也降低了被主动探测识别的概率。&lt;/p&gt;
&lt;h2 id=&quot;九-安全建议&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#九-安全建议&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;九、安全建议&lt;/span&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;UUID、Reality 密钥对、&lt;code&gt;short_id&lt;/code&gt; 全部用生成命令出，不要手编弱值；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;config.json&lt;/code&gt; 权限 &lt;code&gt;600&lt;/code&gt;；私钥只留在服务端，公钥给客户端；&lt;/li&gt;
&lt;li&gt;&lt;code&gt;xtls-rprx-vision&lt;/code&gt; 不要搭配 &lt;code&gt;multiplex&lt;/code&gt;；&lt;/li&gt;
&lt;li&gt;伪装站选 VPS 能出站访问、且不是你自己控制的站点；&lt;/li&gt;
&lt;li&gt;定期升级 sing-box，升级后重新执行 &lt;code&gt;sing-box check&lt;/code&gt;。&lt;/li&gt;
&lt;/ul&gt;
</description>
</item>
<item>
<title>Debian 手动创建 Swap 文件</title>
<link>https://blog.fexumo.org/post/debian-create-swap</link>
<guid isPermaLink="true">https://blog.fexumo.org/post/debian-create-swap</guid>
<pubDate>Sun, 02 Aug 2026 00:00:00 GMT</pubDate>
<description>&lt;p&gt;Swap 可在内存不足时提供磁盘缓冲，但速度远低于 RAM。以下命令需使用 &lt;code&gt;root&lt;/code&gt;，示例创建 1 GB Swap。&lt;/p&gt;
&lt;h2 id=&quot;检查状态&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#检查状态&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;检查状态&lt;/span&gt;&lt;/h2&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-1&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-1&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;swapon --show
free -h&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;创建并启用&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#创建并启用&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;创建并启用&lt;/span&gt;&lt;/h2&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-2&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-2&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;若 &lt;code&gt;fallocate&lt;/code&gt; 创建的文件无法启用，改用：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-3&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-3&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;dd if=/dev/zero of=/swapfile bs=1M count=1024 status=progress
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;用 &lt;code&gt;swapon --show&lt;/code&gt; 确认。&lt;/p&gt;
&lt;h2 id=&quot;设置开机启用&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#设置开机启用&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;设置开机启用&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;确认没有重复配置后，再追加到 &lt;code&gt;/etc/fstab&lt;/code&gt;：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-4&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-4&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;echo '/swapfile none swap sw 0 0' &amp;gt;&amp;gt; /etc/fstab
findmnt --verify&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;调整-swappiness&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#调整-swappiness&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;调整 Swappiness&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;服务器可按负载将默认值 &lt;code&gt;60&lt;/code&gt; 调低到 &lt;code&gt;10&lt;/code&gt;：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-5&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-5&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;echo 'vm.swappiness=10' &amp;gt; /etc/sysctl.d/99-swappiness.conf
sysctl --system
sysctl vm.swappiness&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;长期频繁使用 Swap，通常说明内存不足，应优先优化应用或增加 RAM。&lt;/p&gt;
&lt;h2 id=&quot;删除&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#删除&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;删除&lt;/span&gt;&lt;/h2&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-6&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-6&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;swapoff /swapfile
# 从 /etc/fstab 删除对应行
rm -f /swapfile
swapon --show
free -h&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;激活失败时，检查文件权限是否为 &lt;code&gt;600&lt;/code&gt;；必要时改用 &lt;code&gt;dd&lt;/code&gt;，并查看 &lt;code&gt;dmesg | tail -n 30&lt;/code&gt;。&lt;/p&gt;
</description>
</item>
<item>
<title>你好，Rust</title>
<link>https://blog.fexumo.org/post/hello</link>
<guid isPermaLink="true">https://blog.fexumo.org/post/hello</guid>
<pubDate>Sat, 01 Aug 2026 00:00:00 GMT</pubDate>
<description>&lt;p&gt;这是 fexumo 的第一篇文章：一个纯 Rust、零依赖的静态博客生成器。&lt;/p&gt;
&lt;h2 id=&quot;它包含什么&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#它包含什么&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;它包含什么&lt;/span&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Markdown 渲染：标题、列表、引用、表格、图片和代码块&lt;/li&gt;
&lt;li&gt;RSS、sitemap、响应式布局和文章目录&lt;/li&gt;
&lt;li&gt;分层架构：内容、日期、渲染、文件系统各自独立&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;添加文章&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#添加文章&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;添加文章&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;在 &lt;code&gt;content/&lt;/code&gt; 新建 Markdown 文件：&lt;/p&gt;
&lt;figure class=&quot;code-window&quot; aria-labelledby=&quot;code-1&quot;&gt;&lt;figcaption class=&quot;code-window-bar&quot; id=&quot;code-1&quot;&gt;&lt;span class=&quot;code-dot red&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot yellow&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-dot green&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span class=&quot;code-lang&quot;&gt;markdown&lt;/span&gt;&lt;button class=&quot;code-copy&quot; type=&quot;button&quot; aria-label=&quot;复制代码&quot;&gt;Copy&lt;/button&gt;&lt;/figcaption&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;---
title: 新文章标题
date: 2026-08-01
---
正文从这里开始。&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;文件名会成为 URL slug。构建器负责日期校验、URL 净化、摘要、排序和旧页面清理。&lt;/p&gt;
&lt;h2 id=&quot;交互&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#交互&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;交互&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;首次访问跟随设备明暗模式，可手动切换主题。界面不依赖 hover，也没有鼠标拖尾；点击、触控和键盘操作都可用。&lt;/p&gt;
&lt;h2 id=&quot;为什么用-rust&quot;&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#为什么用-rust&quot; aria-label=&quot;链接到此标题&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;heading-text&quot;&gt;为什么用 Rust&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;标准库已经足够。依赖越少，构建越直接，部署结果越容易检查。当前使用 Rust 1.98 与 2024 edition。&lt;/p&gt;
</description>
</item>
</channel></rss>
