搭建 Hysteria2 教程
适用场景:搭建一个基于 QUIC 的 Hysteria2 代理服务端,利用 sing-box 的 ACME 功能自动签发 TLS 证书,无需手动管理证书文件。
1. 安装 sing-box
bash <(curl -fsSL https://sing-box.app/deb-install.sh)
2. 设置开机自启
sudo systemctl enable sing-box
3. 编辑配置文件
cd /etc/sing-box
vim config.json
4. Hysteria2 配置示例
{
"log": {
"disabled": false,
"level": "error",
"timestamp": true
},
"inbounds": [
{
"type": "hysteria2",
"tag": "hysteria2-in",
"listen": "::",
"listen_port": 你的端口,
"users": [
{
"password": "你的密码"
}
],
"tls": {
"enabled": true,
"alpn": [
"h3"
],
"certificate_path": "",
"key_path": "",
"acme": {
"domain": [
"你的域名"
],
"dns01_challenge": {
"provider": "cloudflare",
"api_token": "你的dns_token"
}
}
}
}
],
"outbounds": [
{
"type": "direct",
"tag": "direct"
}
]
}
配置要点:
listen_port、password、domain、api_token都要替换成你自己的值。- 使用
acme+dns01_challenge(cloudflare)时无需手动放行 80 端口,证书由 sing-box 自动申请并续期。 - 也可以改为
certificate_path/key_path指向手动获取的证书文件。
5. 重启 sing-box
sudo systemctl restart sing-box
常用命令
启用 sudo systemctl enable sing-box
禁用 sudo systemctl disable sing-box
启动 sudo systemctl start sing-box
停止 sudo systemctl stop sing-box
强行停止 sudo systemctl kill sing-box
重启 sudo systemctl restart sing-box
查看日志 sudo journalctl -u sing-box --output cat -e
实时日志 sudo journalctl -u sing-box --output cat -f
验证与自查
sudo systemctl status sing-box显示 active(running)sudo ss -lntup | grep <你的端口>确认 UDP 端口监听正常sudo journalctl -u sing-box --output cat -e无报错,能看到 ACME 证书签发成功日志- 客户端(v2rayN / sing-box / Clash.Meta 等)用 Hysteria2 + 你的密码连接成功,
curl ip.sb出口为服务端 IP