v2ray利用cdn(cloudflare)

最后修改日期:2018-03-28
文章目录

前言

随着某些技术的升级,IP被认证的概率越来越大,但是IP被认证了并不代表着就不能用了。在IP被认证的时候可以使用CDN来中转流量,以继续使用被认证的IP。

使用

准备工作

申请域名,一般来说,我们使用免费的域名注册商freenom.com,在freenom可以免费申请cf,ga,ml,tk域名。
注册cloudflare帐号:cloudflare
按照提示在freenom将域名的NS服务器设置为cloudflare的NS服务器。
在cloudflare的DNS设置中,将A记录指向自己的IP。

v2ray服务端设置。

https://github.com/v2ray/v2ray-core/releases查看并下载适合于自己系统的程序。
这里以ubuntu16.04为例。

apt install unzip -y
wget https://github.com/v2ray/v2ray-core/releases/download/v3.13/v2ray-linux-64.zip
unzip v2ray-linux-64.zip
mv v2ray-v3.13-linux-64 v2ray
cd v2ray

服务端安装使用官方脚本

bash <(curl -L -s https://install.direct/go.sh)

服务端设置

vi /etc/v2ray/config.json

# 把自带的配置全删掉,复制以下内容进去

{
    "log": {
        "access": "/var/log/v2ray/access.log",
        "error": "/var/log/v2ray/error.log",
        "loglevel": "info"
    },
    "inbound": {
        "port": 10000,
        "listen": "127.0.0.1",
        "protocol": "vmess",
        "allocate": {
            "strategy": "always"
        },
        "settings": {
            "clients": [{
                "id": "6d8a82b9-94d6-442e-a340-2b9cd5752c77",
                "level": 1,
                "alterId": 64,
                "security": "chacha20-poly1305"
            }]
        },
        "streamSettings": {
            "network": "ws",
            "wsSettings": {
                "connectionReuse": false,
                "path": "/phpmyadmin/"
            }
        }
    },
    "outbound": {
        "protocol": "freedom",
        "settings": {}
    },
    "outboundDetour": [{
        "protocol": "blackhole",
        "settings": {},
        "tag": "blocked"
    }],
    "routing": {
        "strategy": "rules",
        "settings": {
            "rules": [{
                "type": "field",
                "ip": ["0.0.0.0/8", "10.0.0.0/8", "100.64.0.0/10", "127.0.0.0/8", "169.254.0.0/16", "172.16.0.0/12", "192.0.0.0/24", "192.0.2.0/24", "192.168.0.0/16", "198.18.0.0/15", "198.51.100.0/24", "203.0.113.0/24", "::1/128", "fc00::/7", "fe80::/10"],
                "outboundTag": "blocked"
            }]
        }
    }
}

运行service v2ray start来启动 V2Ray 进程; 之后可以使用service v2ray start|stop|status|reload|restart|force-reload控制 V2Ray 的运行
客户端安装
https://github.com/v2ray/v2ray-core/releases查看并下载适合于自己系统的程序。
(注:V2RAY客户端和服务端一体,只是配置方式的不同,因此此处服务端和客户端在同一个地方下载,但是服务端和客户端的系统可能不同,因此应下载不同版本的程序。windows系统应下载:v2ray-windows-32.zip或者v2ray-windows-64.zip)
修改 config.json 配置为以下内容,注意 address (第25行)填写网站域名。

{
  "log": {
    "access": "",
    "error": "",
    "loglevel": ""
  },
  "inbound": {
    "port": 1085,
    "listen": "0.0.0.0",
    "protocol": "socks",
    "settings": {
      "auth": "noauth",
      "udp": true,
      "ip": "127.0.0.1",
      "clients": null
    },
    "streamSettings": null
  },
  "outbound": {
    "tag": "agentout",
    "protocol": "vmess",
    "settings": {
      "vnext": [
        {
          "address": "网站域名",
          "port": 443,
          "users": [
            {
              "id": "6d8a82b9-94d6-442e-a340-2b9cd5752c77",
              "alterId": 64,
              "security": "chacha20-poly1305"
            }
          ]
        }
      ]
    },
    "streamSettings": {
      "network": "ws",
      "security": "tls",
      "tcpSettings": null,
      "kcpSettings": null,
      "wsSettings": {
        "connectionReuse": true,
        "path": "/phpmyadmin/",
        "headers": null
      }
    },
    "mux": {
      "enabled": true
    }
  },
  "inboundDetour": null,
  "outboundDetour": [
    {
      "protocol": "freedom",
      "settings": {
        "response": null
      },
      "tag": "direct"
    },
    {
      "protocol": "blackhole",
      "settings": {
        "response": {
          "type": "http"
        }
      },
      "tag": "blockout"
    }
  ],
  "dns": {
    "servers": [
      "8.8.8.8",
      "8.8.4.4",
      "localhost"
    ]
  },
  "routing": {
    "strategy": "rules",
    "settings": {
      "domainStrategy": "IPIfNonMatch",
      "rules": [
        {
          "type": "field",
          "port": null,
          "outboundTag": "direct",
          "ip": [
            "0.0.0.0/8",
            "10.0.0.0/8",
            "100.64.0.0/10",
            "127.0.0.0/8",
            "169.254.0.0/16",
            "172.16.0.0/12",
            "192.0.0.0/24",
            "192.0.2.0/24",
            "192.168.0.0/16",
            "198.18.0.0/15",
            "198.51.100.0/24",
            "203.0.113.0/24",
            "::1/128",
            "fc00::/7",
            "fe80::/10"
          ],
          "domain": null
        },
        {
          "type": "field",
          "port": null,
          "outboundTag": "direct",
          "ip": null,
          "domain": [
            "geosite:cn"
          ]
        },
        {
          "type": "field",
          "port": null,
          "outboundTag": "direct",
          "ip": [
            "geoip:cn"
          ],
          "domain": null
        }
      ]
    }
  }
}

安装并设置nginx

centos

yum update
yum install nginx -y

debian/ubuntu

apt update
apt install nginx -y

有些debian/ubuntu系统可能自带apache2,此时应卸载apache2

apt remove apache* -y

修改nginx默认配置

vi /etc/nginx/sites-available/default

# 在 server 内插入以下内容,同时开启 error_page

location /phpmyadmin/ {
          proxy_redirect off;
          #proxy_pass http://127.0.0.1:10000;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
          proxy_set_header Host $http_host;
          proxy_intercept_errors on;
          if ($http_upgrade = "websocket" ){
             proxy_pass http://127.0.0.1:10000;
          }
        }

重启nginx。

service nginx restart

此时启用你的客户端,应该就可以实现利用CDN中转了。
客户端运行 v2ray 或 v2ray.exe,直接运行即可

本地 socks 代理为 127.0.0.1:1085

第三方客户端配置 address(网站域名)、port(443)、id(很长那串)、alterId(64)、security(chacha20-poly1305)、network(ws)、path(/v2ray/)、底层传输安全(tls)
另外由于使用CDN中转之后链接速度会很慢,因此应酌情启用。
参考链接:
https://github.com/iMeiji/shadowsocks_install/wiki/Project-V-%E9%85%8D%E7%BD%AE-WebSocket-TLS-Web-CDN

发表评论