Featured image of post Hysteria2

Hysteria2

Hysteria2

开始前的准备工作

  1. 需要一个域名
  2. 一台vps(支持UDP)
  3. 在开始搭建之前先把域名解析到你需要搭建Hysteria2的vps ip

首先安装服务端

这里使用官方提供的一键脚本

1
bash <(curl -fsSL https://get.hy2.sh/)

配置服务端

编辑配置文件,存放于 /etc/hysteria/ 目录下

1
nano /etc/hysteria/config.yaml

根据自己需求修改示例配置中的参数值

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# listen: :443   # 服务器默认在 443 端口监听。如果你想更改端口,取消这行注释。如果只指定了端口号(没有地址),如示例中所示,它将默认同时监听 IPv4 和 IPv6。要仅监听 IPv4,可以使用 0.0.0.0:443。要仅监听 IPv6,可以使用 [::]:443。

acme:
  domains:
    - your.domain.net   # 用你的域名替换
  email: [email protected]   # 用你的邮件地址替换

auth:
  type: password
  password: Se7RAuFZ8Lzg   # 选择一个强密码进行替换

masquerade: 
  type: proxy
  proxy:
    url: https://news.ycombinator.com/   # 替换为你想伪装成的网站的 URL
    rewriteHost: true 

自签证书方法

1
openssl req -x509 -nodes -newkey ec:<(openssl ecparam -name prime256v1) -keyout /etc/hysteria/server.key -out /etc/hysteria/server.crt -subj "/CN=bing.com" -days 36500 && sudo chown hysteria /etc/hysteria/server.key && sudo chown hysteria /etc/hysteria/server.crt

服务端配置文件(修改好直接复制进vps终端)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
cat << EOF > /etc/hysteria/config.yaml
listen: :443 
tls:
  cert: /etc/hysteria/server.crt
  key: /etc/hysteria/server.key

auth:
  type: password
  password: 123456 # 改成自己的强密码 

masquerade:
  type: proxy
  proxy:
    url: https://bing.com 
    rewriteHost: true

EOF

如需进一步定制,请参考完整服务端配置

启动服务端

1
systemctl start hysteria-server.service

设置开机自启

1
systemctl enable hysteria-server.service

查看状态

1
systemctl status hysteria-server.service

一些常用指令

重启

1
systemctl restart hysteria-server.service

停止

1
systemctl stop hysteria-server.service

日志

1
journalctl -u hysteria-server.service

删除

1
bash <(curl -fsSL https://get.hy2.sh/) --remove
使用 Hugo 构建
主题 StackJimmy 设计