如果说HTTP是单工通讯的话,WebSocket则是HTML5开始提供的一种在单个TCP连接上进行全双工通讯的协议,由此便产生了新的代理形式。
Github:
https://github.com/lzjluzijie/websocks
安装Websocks:
wget https://github.com/lzjluzijie/websocks/releases/download/v0.5.0/websocks_Linux_x86_64.tar.gz
tar -xzvf websocks_Linux_x86_64.tar.gz
chmod +x websocks
安装Caddy:
Websocks采用TLS加密,用户也可以使用Caddy实现TLS,若采用后者,则需要安装Caddy,可自动申请Let’s Encrypt的TLS证书。
wget https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/caddy_install.sh
chmod +x caddy_install.sh
./caddy_install.sh
Caddy配置文件Caddyfile(/usr/local/caddy/Caddyfile):
https://域名 {
proxy /密码 localhost:监听端口 {
websocket
}
}
启动/停止/重启Caddy:
service caddy start/stop/restart
或
systemctl start/stop/restart caddy
Caddy自动申请SSL证书位置:
/.caddy/acme/acme-v01.api.letsencrypt.org/sites/xxx.xxx(域名)/
卸载 Caddy:
./caddy_install.sh uninstall
Systemd配置:
vi /etc/systemd/system/websocks.service
内容:
[Unit]
Description=websocks
[Service]
ExecStart=/root/websocks server -l 127.0.0.1:监听端口 -p /密码
(若使用内置TLS,应为:ExecStart=/root/websocks server -l 127.0.0.1:监听端口 -p /密码 https://www.debian.org/ --tls)
Restart=always
[Install]
WantedBy=multi-user.target
运行/停止/重启Websocks:
service websocks start/stop/restart
或
systemctl start/stop/restart websocks.service
设为自启动:
systemctl enable websocks.service
客户端配置:
内置 TLS:
./websocks client -l :1080 -s wss://the-real-server.com:2333/密码 -n www.debian.org --insecure
Caddy TLS:
./websocks client -l :1080 -s wss://server.com/密码