Hysteria 2 服务器搭建指南 | AI生成和翻译

Home 2026.01

Question: 如何在服务器上设置 Hysteria 2?

Answer:

这是一份清晰且最新的指南(截至 2026 年),用于在 Linux VPS(最常见的情况,如 Ubuntu/Debian/CentOS 等)上部署 Hysteria 2 服务器。

Prerequisites

这是 Linux 服务器最简单且持续维护的方法。

  1. 运行官方 bash 脚本(安装 binary 并创建 systemd service):
    bash <(curl -fsSL https://get.hy2.sh/)
    
    • 它会根据你的架构(amd64/arm64)下载最新的 Hysteria 2 binary
    • 安装到 /usr/local/bin/hysteria
    • 创建 /etc/hysteria/config.yaml(示例配置)
    • 设置 systemd service:hysteria-server.service
  2. 编辑配置文件:
    nano /etc/hysteria/config.yaml
    

    最小化可行示例(ACME 自动证书 + password 认证):

    listen: :443
    
    acme:
      domains:
        - your.domain.com           # ← 更改为你的域名
      email: your@email.com         # ← 用于 Let's Encrypt 的邮箱
    
    auth:
      type: password
      password: YOUR_STRONG_PASSWORD_HERE   # ← 更改此处!
    
    masquerade:
      type: proxy
      proxy:
        url: https://news.ycombinator.com/   # ← 伪装站点(有助于应对 DPI)
        rewriteHost: true
    

    另一种方案(如果你已经有了自己的 cert/key):

    listen: :443
    
    tls:
      cert: /path/to/fullchain.pem
      key: /path/to/privkey.pem
    
    auth:
      type: password
      password: YOUR_STRONG_PASSWORD_HERE
    
    masquerade:
      type: proxy
      proxy:
        url: https://www.bing.com/
        rewriteHost: true
    

    配置说明:

    • 端口 443 是默认端口且强烈推荐(看起来像正常的 HTTP/3)
    • masquerade 让服务器响应像一个真实的网站 → 极难被屏蔽
    • 对于个人使用,你可以完全删除 bandwidth 限制(或设置得非常高)
    • 保存并退出
  3. 启动并启用服务:
    systemctl start hysteria-server
    systemctl enable hysteria-server
    
  4. 检查状态和日志:
    systemctl status hysteria-server
    journalctl -u hysteria-server -e -f
    

    查找:server up and running → 成功!

Alternative: 手动安装(不用脚本)

  1. 下载最新 binary:
    wget https://download.hysteria.network/app/latest/hysteria-linux-amd64   # 或 -arm64
    chmod +x hysteria-linux-amd64
    mv hysteria-linux-amd64 /usr/local/bin/hysteria
    
  2. 允许非 root 用户绑定低位端口:
    setcap cap_net_bind_service=+ep /usr/local/bin/hysteria
    
  3. 按照上文创建配置文件(例如 /etc/hysteria/config.yaml)。

  4. 手动运行(进行调试):
    hysteria server -c /etc/hysteria/config.yaml
    
  5. 自行创建 systemd service(或使用上述脚本方法)。

Firewall (以 ufw 为例)

ufw allow 443/udp
ufw reload

After Setup

Common Tips / Troubleshooting

References:


Back

x-ai/grok-4.1-fast

Donate