Skip to content

Instantly share code, notes, and snippets.

@diyism
Last active June 18, 2024 17:21
Show Gist options
  • Save diyism/2eeb4f3811d6391780cbfa9dd19bb9de to your computer and use it in GitHub Desktop.
Save diyism/2eeb4f3811d6391780cbfa9dd19bb9de to your computer and use it in GitHub Desktop.
v2ray wss over cloudflare 8443 proxy
use "time curl --socks5 localhost:8081 https://1.1.1.1 | head -n 20" to compare naiveproxy, v2ray, wssocks, and qv2ray:
naive quic direct: 0.4s
naive http2 direct: 0.4s
v2ray over cloudflare wss: 0.4s to 0.7s
wssocks-linux-amd64 over cloudflare wss: 0.6s
qv2ray gun over cloudflare grpc 0.7s to 0.9s
(naive http2 won't proxy over cloudflare: Network/http2/help: "The connection from Cloudflare to your origin will be made over HTTP 1.x")
wssocks has no traffic obfuscation, can't use it in china for long term,
v2ray is not stable,
naive proxy is best: https://gist.github.com/diyism/d7c8905040a1010d55a278ef1d1a4f40
qv2ray gun is ok: https://gist.github.com/diyism/642ed3b0330f3224eb622c71daa9b1f5
=====================v2ray over cloudflare wss==================
#ssh into VPS
mkdir v2ray
cd v2ray
wget https://github.com/v2ray/dist/raw/master/v2ray-linux-64.zip
unzip v2ray-linux-64.zip
v2uuid=$(cat /proc/sys/kernel/random/uuid)
read domain
cat >config.json<<EOF
{
"inbounds": [
{
"port": 18443,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "$v2uuid"
}
]
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/wss"
}
}
}
],
"outbounds": [
{
"protocol": "freedom",
"settings": {}
}
]
}
EOF
while true; do nohup ./v2ray >/dev/null 2>&1; sleep 1; done &
#modify Caddyfile to use another port 8443 that cloudflare supports:
cat >>Caddyfile<<EOF
https://<domain>:8443 {
respond / "Hello, world!"
@websocket {
path /wss
header Connection Upgrade
header Upgrade websocket
}
reverse_proxy @websocket 127.0.0.1:18443
}
EOF
#restart caddy server
#login https://dash.cloudflare.com/
#click "add a site" to add your domain name
#click "your domain/DNS" in left side menu
#click "edit" of your domain name "A" record, switch on "proxy status", click "save"
#click "your domain/SSL/TLS" in left side menu
#click "Full (strict)" to enable it
#click "your domain/Network" in left side menu
#click "Websockets" to eanble "WebSockets connections to your origin server"
# exit your VPS
exit
# at local machine:
mkdir v2ray
cd v2ray
wget https://github.com/v2ray/dist/raw/master/v2ray-linux-64.zip
unzip v2ray-linux-64.zip
cat >client.json<<EOF
{
"inbounds": [{
"protocol": "socks",
"listen": "127.0.0.1",
"port": 8082,
"settings": {
"auth": "noauth",
"udp": false
}
}],
"outbounds": [
{
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "<domain>",
"port": 443,
"users": [
{
"id": "<v2uuid>"
}
]
}
]
},
"streamSettings": {
"network": "ws",
"security": "tls",
"wsSettings": {
"path": "/wss"
}
},
"mux": {
"enabled": true
}
}
]
}
EOF
while true; do nohup ./v2ray -c client.json >/dev/null 2>&1; sleep 1; done &
#if there's problem, we can test wss:
npm install -g wscat
wscat -c "wss://<domain>:8443/wss"
#if it show "Connected (press CTRL+C to quit)", the wss server is ok
#if the cloudflare assigned IP of your domain has been blocked or too slow,
#you can use CloudflareST to scan all cloudflare IPs to find fastest one:
#https://github.com/XIU2/CloudflareSpeedTest
#edit /etc/hosts, add "<fasted cloudflare cdn ip> <your domain>" into it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment