v2Ray 是 Project V 下的一个工具。Project V 是一个包含一系列构建特定网络环境工具的项目,而 V2Ray 属于最核心的一个。
此文章主要介绍服务器端v2ray有关内容。
安装v2ray
在服务器执行下面命令
bash <(curl -L -s https://install.direct/go.sh)
此脚本会自动安装以下文件
/usr/bin/v2ray/v2ray:V2Ray 程序;/usr/bin/v2ray/v2ctl:V2Ray 工具;/etc/v2ray/config.json:配置文件;/usr/bin/v2ray/geoip.dat:IP 数据文件/usr/bin/v2ray/geosite.dat:域名数据文件
此脚本会配置自动运行脚本。自动运行脚本会在系统重启之后,自动运行 V2Ray。目前自动运行脚本只支持带有 Systemd 的系统,以及 Debian / Ubuntu 全系列。
取消自启动,可执行下面命令
systemctl disable v2ray
WebSocket+TLS+Web
使用此方法的配置,是为了更好的流量伪装,尽量减少GFW封服务器IP。
v2ray配置
将下面配置,修改后覆盖 /etc/v2ray.conf 文件
{ "inbounds": [ { "port": 10000, "listen":"127.0.0.1",//只监听 127.0.0.1,避免除本机外的机器探测到开放了 10000 端口 "protocol": "vmess", "settings": { "clients": [ { "id": "b831381d-6324-4d53-ad4f-8cda48b30811", // 修改成独有的id,可通过 uuidgen 命令生成UUID "alterId": 64 } ] }, "streamSettings": { "network": "ws", "wsSettings": { "path": "/ray" // 此路径可自定义 } } } ], "outbounds": [ { "protocol": "freedom", "settings": {} } ] }
Nginx配置
server { listen 443 ssl; ssl on; ssl_certificate /etc/v2ray/v2ray.crt; ssl_certificate_key /etc/v2ray/v2ray.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; server_name mydomain.me; location /ray { # 与 V2Ray 配置中的 path 保持一致 proxy_redirect off; proxy_pass http://127.0.0.1:10000;#假设WebSocket监听在环回地址的10000端口上 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $http_host; # Show realip in v2ray access.log proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }