Docker 部署 V2ray 实现翻墙

首先需要有一个境外VPS

其次 要安装了docker环境

获取v2ray镜像

[root@izj6c0lnj9ce66mh9hfw3sz ~]# docker pull v2ray/official
Using default tag: latest
latest: Pulling from v2ray/official
050382585609: Pull complete 
f416db6693ab: Pull complete 
90feb2e67794: Pull complete 
bd0ce73aa2c6: Pull complete 
90df5753f396: Pull complete 
9a9c0864356d: Pull complete 
0f5e23c9ecd1: Pull complete 
Digest: sha256:1b3e47d56bb2e012b4a3dfad53e9385cd04cf85025eb504d0039eff046589507
Status: Downloaded newer image for v2ray/official:latest
docker.io/v2ray/official:latest

创建配置文件

//创建文件夹
[root@izj6c0lnj9ce66mh9hfw3sz ~]# mkdir /etc/v2ray

//编辑配置文件
[root@izj6c0lnj9ce66mh9hfw3sz ~]# vim /etc/v2ray/config.json

配置文件内容 (实际部署过程中 把下面的注释都删掉)

{
  "inbounds": [
    {
      //监听端口
      "port": 6701,
      //注意  这里如果不填0.0.0.0的话  docker外访问不到
      "listen": "0.0.0.0",
      "protocol": "vmess",
      "settings": {
        "clients": [
          {
            //id 可自行设置
            "id": "0d315150f02d4235bfd5438906c0c4d0",
            "alterId": 64
          }
        ]
      },
      "streamSettings": {
        "network": "ws",
        "wsSettings": {
          //路径  跟nginx 反代 路径一致即可
          "path": "/ray"
        }
      }
    }
  ],
  "outbounds": [
    {
      "protocol": "freedom",
      "settings": {}
    }
  ]
}

启动v2ray

[root@izj6c0lnj9ce66mh9hfw3sz ~]# docker run -d --name v2ray -v /etc/v2ray:/etc/v2ray -p 6701:6701 v2ray/official v2ray -config=/etc/v2ray/config.json
48acf5ea514da61508ac8952d01ed3a7cb8a9ec2ddbb9f8cb88e629e3d6d0c1b

初步测试 是否通过

在docker外 访问端口 测试是否正常 如果正常的话 应该像下面这样

会返回字符串 " Bad Request "

[root@izj6c0lnj9ce66mh9hfw3sz ~]# curl 127.0.0.1:6701/ray
Bad Request

设置 Nginx 反代

server {
  listen 443 ssl;
  ssl on;
  ## 证书
  ssl_certificate /usr/local/tools/https_cret/full_chain.pem;
  ssl_certificate_key /usr/local/tools/https_cret/private.key;
  ssl_protocols         TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers           HIGH:!aNULL:!MD5;
  ## 域名
  server_name           mydoman.com;
  ## ray 为v2ray的ws path
  location /ray {
          proxy_redirect off;
          ## v2ray 的监听端口
          proxy_pass http://127.0.0.1:6701;
          proxy_http_version 1.1;
          ## 域名
          proxy_set_header Host "mydoman.com";
          proxy_set_header Connection "Upgrade";
          proxy_set_header Upgrade "WebSocket";
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_intercept_errors on;
  }
}

最后客户端设置

这里我使用的是Mac OS 上的 V2rayU 客户端

QQ20200208-161730@2x