VPS搭建v2@ray+Websocket配置与使用教程及配置文件

DevOps
2021-07-28 / 0 评论 / 155 阅读 / 正在检测是否收录...

前言

  官方VPS一键搭建v2@ray后上传配置文件即可,无多余操作。

环境信息

  操作系统:CentOS 7、Debian 9、Ubuntu 18以上版本系统均可
  VPS服务器: BandwvagonCloudCone 、 Vultr
  推荐以上三家比较稳定!!!

安装v2@ray

1.通过ssh连接服务器

2.校准服务器时间

  对于 v2@ray,它的验证方式包含时间,就算是配置没有任何问题,如果时间不正确,也无法连接 v2@ray 服务器的,服务器会认为你这是不合法的请求。所以系统时间一定要正确,只要保证时间误差在90 秒之内就没问题。
  对于 VPS(Linux) 可以执行命令 date -R 查看时间:

$ date -R
Sun, 22 Jan 2017 10:10:36 -0500

  输出结果中的 -0500 代表的是时区为西 5 区,如果转换成东 8 区时间则为 2017-01-22 23:10:36。
  如果时间不准确,可以使用 date --set 修改时间:

$ sudo date --set="2017-01-22 16:16:23"
Sun 22 Jan 16:16:23 GMT 2017

  如果你的服务器架构是 OpenVZ,那么使用上面的命令有可能修改不了时间,直接发工单联系 VPS 提供商的客服吧,就说你在 VPS 上运行的服务对时间有要求,要他们提供可行的修改系统时间的方法。
  对 VPS 的时间校准之后接着是个人电脑,如何修改电脑上的时间我想不必我多说了。
  无论是 VPS 还是个人电脑,时区是什么无所谓,因为 v2@ray 会自动转换时区,但是时间一定要准确。

2.执行一下命令行安装v2@ray

bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)

  大约几十秒钟时间即可看到以下内容时什么已经安装完毕。

installed: /usr/local/bin/v2@ray
installed: /usr/local/bin/v2ctl
installed: /usr/local/share/v2@ray/geoip.dat
installed: /usr/local/share/v2@ray/geosite.dat
installed: /usr/local/etc/v2@ray/00_log.json
installed: /usr/local/etc/v2@ray/01_api.json
installed: /usr/local/etc/v2@ray/02_dns.json
installed: /usr/local/etc/v2@ray/03_routing.json
installed: /usr/local/etc/v2@ray/04_policy.json
installed: /usr/local/etc/v2@ray/05_inbounds.json
installed: /usr/local/etc/v2@ray/06_outbounds.json
installed: /usr/local/etc/v2@ray/07_transport.json
installed: /usr/local/etc/v2@ray/08_stats.json
installed: /usr/local/etc/v2@ray/09_reverse.json
installed: /var/log/v2@ray/
installed: /var/log/v2@ray/access.log
installed: /var/log/v2@ray/error.log
installed: /etc/systemd/system/[email protected]
installed: /etc/systemd/system/v2@[email protected]
removed: /tmp/tmp.vk9AF2EqKA/
info: v2@ray v4.27.0 is installed.
You may need to execute a command to remove dependent software: apt remove curl unzip
Please execute the command: systemctl enable v2@ray; systemctl start v2@ray

配置文件

  复制一下配置信息在本地创建名为config.json文件

{
  "log" : {
    "loglevel": "warning"
  },
  "inbound": {
    "port": 1096, //(此端口与nginx配置相关)
    "listen": "127.0.0.1",
    "protocol": "vmess",
    "settings": {
      "clients": [
        {
          "id": "0570b298-5d89-4f2e-ab11-fe3f28a77268", //你的UUID, 此ID需与客户端保持一致
          "level": 1,
          "alterId": 64 //此ID也需与客户端保持一致
        }
      ]
    },
   "streamSettings":{
      "network": "ws",
      "security": "none",
      "wsSettings": {
           "path": "/ray" //与nginx配置相关
      }
   }
  },
  "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"
        }
      ]
    }
  }
}

  上传至服务器/usr/local/etc/v2@ray

设置v2@ray开机启动

systemctl enable v2@ray
将上面@去掉

运行v2ray

systemctl start v2@ray
将上面@去掉

设置域名反代理(不需要域名可直接跳过)

nginx反代理配置

#PROXY-START/ray
location /ray #/ray与配置文件上一致
{
    proxy_pass http://127.0.0.1:1096;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    #持久化连接相关配置
    #proxy_connect_timeout 30s;
    #proxy_read_timeout 86400s;
    #proxy_send_timeout 30s;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    add_header X-Cache $upstream_cache_status;
    
    #Set Nginx Cache
    
        add_header Cache-Control no-cache;
}
#PROXY-END/ray

客户端配置

v2@ray客户端配置

2
您的大名:
万水千山总是情,给个打赏行不行。 打赏

评论 (0)

取消
在线咨询!