中文 English

Bypassing the Firewall or Setting Up a Server Farm: V2Ray Configuration with WebSocket + TLS + Web + CDN

Published: 2021-01-26
proxy FuckGFW GFW websocket tls web cdn v2ray caddy2

v2ray The most secure configuration currently is WebSocket + TLS + Web + CDN. It uses port 443: direct access shows a website, but after connecting with a client it becomes a proxy tool. From the outside it looks like an electric shaver, but it is actually a hair dryer.

1. Check if the system’s time and timezone are correct, otherwise normal connection will not be possible

date
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
date

2. Prepare your own overseas VPS server

Recommended: VPEasy, established provider, lowest plan 1024M/1CPU/25G SSD/1T bandwidth, KVM architecture, $28 per year, first year use FirstYear promo code for 25% off. Author has been purchasing for 6 years, already used for 6 years.

3. Prepare your own CloudFlare account and domain

3.1. Currently the cheapest domains in China

Visit https://cloud.tencent.com/act/pro/DNSPodDomainsCarnival, claim 2 pieces of 5 yuan coupons Then register a .xyz domain with less than 10 digits, new registration 8 yuan, renewal 8 yuan During registration, you can use the 5 yuan coupon, bringing it down to just 3 yuan Then immediately renew for 1 year, can use the 5 yuan coupon again, bringing it down to just 3 yuan Remember: domestic domain registration requires real-name verification

3.2. Registering domain overseas

Recommended: https://namesilo.com, recommend a .top domain, $4.89 per year Below is namesile.com method for modifying domain nameserver, for reference only

Entry: https://www.cloudflare.com

4. Install Caddy2

Other options for providing web services are Nginx and Apache, why choose Caddy2? Because it’s simple and can automatically apply for SSL certificates. The Caddy in the original article can no longer be installed normally from the official website, here is how to install Caddy2

Optional: download from official website, or download from this site

Download from official website Caddy2

Download from this site Caddy2

mkdir -p ~/tools/caddy
cd ~/tools/caddy
wget -O caddy2 https://download.margrop.net/d/oneindex/CENTOS/caddy2_2.2.1
chmod +x caddy2
caddy2 -version

5. Install v2ray

bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)
installed: /usr/local/bin/v2ray
installed: /usr/local/bin/v2ctl
installed: /usr/local/share/v2ray/geoip.dat
installed: /usr/local/share/v2ray/geosite.dat
installed: /usr/local/etc/v2ray/config.json
installed: /var/log/v2ray/
installed: /var/log/v2ray/access.log
installed: /var/log/v2ray/error.log
installed: /etc/systemd/system/v2ray.service
installed: /etc/systemd/system/v2ray@.service
removed: /tmp/tmp.iO3bDdOqa9
info: V2Ray v4.33.0 is installed.
You may need to execute a command to remove dependent software: yum remove curl unzip
Please execute the command: systemctl enable v2ray; systemctl start v2ray

6. Configure and start v2ray

vim /usr/local/etc/v2ray/config.json

Mac/Unix/Linux systems: enter uuidgen in console, this generates UUID Windows systems: enter [guid]::NewGuid() in PowerShell console, this generates UUID

{
  "inbound": {
    "port": 10000,
    "listen":"127.0.0.1",
    "protocol": "vmess",
    "settings": {
      "clients": [
        {
          "id": "E5B33B5A-A241-4246-B8D9-A260FBBAFCCF",
          "alterId": 64
        }
      ]
    },
    "streamSettings": {
      "network": "ws",
      "wsSettings": {
      "path": "/{RANDOM_PATH}"
      }
    }
  },
  "outbound": {
    "protocol": "freedom",
    "settings": {}
  }
}
systemctl start v2ray
systemctl enable v2ray

7. Configure Caddyfile2

Create Caddyfile2 file in /etc/caddy directory, create directory if it doesn’t exist, edit Caddyfile2 file

mkdir /etc/caddy
cd /etc/caddy
vim /etc/caddy/Caddyfile2
blog.margrop.net
{
    root * /usr/share/caddy
    file_server
    log {
        output file /var/log/caddy/vps.log
    }
    tls {
        dns cloudflare g9_uKv1RrXXXXXXHOPfXXXXXXYNZGXXXXXXJh3qp
    }
    @v2ray_websocket {
        path /{RANDOM_PATH}
        header Connection *Upgrade*
        header Upgrade websocket
    }
    reverse_proxy @v2ray_websocket localhost:10000
}

8. Configure Caddy JSON

cd ~/tools/caddy
./caddy2 adapt --config /etc/caddy/Caddyfile2 > ~/tools/caddy/config.json
cat ~/tools/caddy/config.json

9. Start and upload Caddy JSON

cd ~/tools/caddy
./caddy2 start
curl localhost:2019/config/
curl localhost:2019/load -X POST -H "Content-Type: application/json" -d @config.json
curl localhost:2019/config/

10. v2ray client configuration

{
    "inbounds": [
        {
            "port": 1080,
            "listen": "0.0.0.0",
            "protocol": "socks",
            "domainOverride": [
                "tls",
                "http"
            ],
            "settings": {
                "auth": "noauth",
                "udp": false
            }
        },
        {
            "port": 1081,
            "listen": "0.0.0.0",
            "protocol": "http",
            "domainOverride": [
                "tls",
                "http"
            ],
            "settings": {
                "auth": "noauth",
                "udp": false
            }
        }
    ],
    "outbound": {
        "protocol": "vmess",
        "settings": {
            "vnext": [
                {
                    "address": "blog.margrop.net",
                    "port": 443,
                    "users": [
                        {
                            "id": "E5B33B5A-A241-4246-B8D9-A260FBBAFCCF",
                            "alterId": 64
                        }
                    ]
                }
            ]
        },
        "streamSettings": {
            "network": "ws",
            "security": "tls",
            "wsSettings": {
                "path": "/{RANDOM_PATH}"
            }
        }
    }
}

UUID, domain, and {RANDOM_PATH} must match the server configuration.

11. Trial run

看看有没有报错,没有报错就访问下网站看是否正常,如果正常就证明caddy2配置无误。

All operations above personally verified on CentOS 7, it works. This document is currently a simplified operation guide, will gradually add detailed operation steps for each step in the future.

12. Configure Caddy2 to auto-start

Create or edit caddy2.service file Edit the service file using the following command:

sudo nano /etc/systemd/system/caddy2.service

Update the service file content with the following

[Unit]
Description=Start Caddy with Config on Boot
After=network.target

[Service]
User=root
WorkingDirectory=/root/tools/caddy
ExecStart=/root/tools/caddy/caddy2 run --config /root/tools/caddy/config.json
wqRestart=on-failure
Environment=HOME=/root

[Install]
WantedBy=multi-user.target

Reload systemd configuration and start the service After saving and closing the file, execute the following commands:

sudo systemctl daemon-reload
sudo systemctl restart caddy2.service
sudo systemctl enable caddy2.service

Verify service status Check if service is running normally:

sudo systemctl status caddy2.service

13. Archive, Caddy1 usage method

#测试运行
caddy -agree -conf /etc/caddy/Caddyfile
#正式运行
nohup caddy -agree -conf /etc/caddy/Caddyfile > /root/caddy.log 2>&1 &

References

V2Ray configuration with WebSocket + TLS + Web WebSocket+TLS+Web Module dns.providers.cloudflare Caddyfile Quick-start Install