宝塔配置中转V2ray 实现v2ray域名中转域名 域名中转直连 直连中转直连
简介
一般我们使用v2ray服务器,都是直接到这个服务器上,进行数据代理转发。就是常用的客户端=> v2ray服务器模式,实际可以客户端=> v2ray中转服务器1 => v2ray中转服务器2 => v2ray努力,设置N个服务器,但设置一定会影响访问速度,所以错误设置了这些用处。
我们来看看如何配置 v2ray 中转服务器。
域名中转只是config.json文件的不同,其余都是一样
1、安装脚本
======
运行以下脚本即可:
curl -Ls https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh | sudo bash
里面可能会有些报错信息,暂时不管,完成之后就是配置了
2、获取用户ID
========
之前的脚本,不用手动配置脚本即可使用,现在使用以上脚本,需要自己配置config.json文件,首先获取用户ID:
运用指令:cat /proc/sys/kernel/random/uuid 创建一个用户 id ,并记住这个id号;
[root@vultr ~]``# cat /proc/sys/kernel/random/uuid
08ef6234-dcc0-45d1-9954-f9490cb2beb2
3、配置
====
配置文件路径为/usr/local/etc/v2ray/config.json,可以使用vi指令打开文本,我个人喜欢使用SSH图形化SFTP客户端,这样对文件的操作和windows一样,非常好用,那我就推荐WinSCP这个工具,进入上面路径,下载config.json文件,进行配置。
下面配置为域名中转域名
{
"inbound": {
"listen":"127.0.0.1",
"port": 10000,
"protocol": "vmess",
"settings": {
"udp": true,
"clients": [
{
"id": "ced93de4-b2f9-4e79-876e-33dddb65d8f7",
"alterId": 64
}
]
},
"streamSettings": {
"network":"ws",
"wsSettings":{
"path":"/r"//中转服务器1的path
}
}
},
"outbound" : {
"mux" : {
"concurrency" : 8,
"enabled" : true
},
"protocol" : "vmess",
"settings" : {
"vnext" : [
{
"users" : [
{
"id" : "f3d90546-3d57-4553-9674-8d4bec893f12",//翻墙服务器的用户UUID
"alterId" : 64,
"security" : "auto"
}
],
"address" : "翻墙服务器的域名",//注意,是翻墙服务器的域名
"port" : 443
}
]
},
"streamSettings" : {
"security" : "tls",
"wsSettings" : {
"headers" : {
"Host" : "翻墙服务器的域名"//注意,是翻墙服务器的域名
},
"path" : "/r"//翻墙服务器的path
},
"network" : "ws",
"tlsSettings" : {
"allowInsecure" : false,
"serverName" : "翻墙服务器的域名"//注意,是翻墙服务器的域名
}
}
},
"inboundDetour": [],
"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"
}
]
}
}
}
下面配置为域名中转直连
{
"inbounds":[
{
"port":10000,
"listen":"127.0.0.1", //此处记得写127.0.0.1,只监听本地
"protocol":"vmess",
"settings":{
"clients":[
{
"id":"f9e620c3-f305-43ed-b98a-25930be56abc", //客户端链接用的密码
"alterId":64
}
]
},
"streamSettings":{
"network":"ws",
"wsSettings":{
"path":"/r" //说明:此处请替换你想写的path分流路径
}
}
}
],
"outbound" : {
"mux" : {
"concurrency" : 8,
"enabled" : true
},
"protocol" : "vmess", // 目标 v2ray 服务器的协议
"settings" : {
"vnext" : [
{
"users" : [
{
"id" : "08ef6234-dcc0-46d1-9954-f9490cb2beb2", // 目标 v2ray 服务器的 vmess 协议需要配置的 uid
"alterId" : 64 // 和目标服务器保持一致
}
],
"address" : "1.1.1.1", // 目前 v2ray 服务器的ip 地址或域名
"port" : 10000 // 目标 v2ray 服务器的开放的对外端口
}
]
},
"streamSettings": {
"network": "tcp", // 记得配置 tcp
"security": "none",
"tlsSettings": {},
"tcpSettings": {},
"httpSettings": {},
"kcpSettings": {
"mtu": 1350,
"tti": 50,
"uplinkCapacity": 100,
"downlinkCapacity": 100,
"congestion": false,
"readBufferSize": 2,
"writeBufferSize": 2,
"header": {
"type": "none"
}
},
"wsSettings": {},
"quicSettings": {}
}
},
"inboundDetour": [],
"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"
}
]
}
}
}
下面配置为直连中转直连
{
"inbound": {
"port": 10000, // docker 内部 v2ray 的端口
"protocol": "vmess", // 我这里使用的 vmess 协议,也可以使用其他协议
"settings": {
"clients": [
{
"id": "f9e620c3-f305-45ed-b98a-25930be56abc", // vmess 协议需要配置的 uid
"alterId": 64
}
]
}
},
"outbound" : {
"mux" : {
"concurrency" : 8,
"enabled" : true
},
"protocol" : "vmess", // 目标 v2ray 服务器的协议
"settings" : {
"vnext" : [
{
"users" : [
{
"id" : "08ef6234-dcc0-46d1-9954-f9490cb2beb2", // 目标 v2ray 服务器的 vmess 协议需要配置的 uid
"alterId" : 64 // 和目标服务器保持一致
}
],
"address" : "1.1.1.1", // 目前 v2ray 服务器的ip 地址或域名
"port" : 10000 // 目标 v2ray 服务器的开放的对外端口
}
]
},
"streamSettings": {
"network": "tcp", // 记得配置 tcp
"security": "none",
"tlsSettings": {},
"tcpSettings": {},
"httpSettings": {},
"kcpSettings": {
"mtu": 1350,
"tti": 50,
"uplinkCapacity": 100,
"downlinkCapacity": 100,
"congestion": false,
"readBufferSize": 2,
"writeBufferSize": 2,
"header": {
"type": "none"
}
},
"wsSettings": {},
"quicSettings": {}
}
},
"inboundDetour": [],
"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"
}
]
}
}
}
直接复制我上面的配置即可使用,id就是上面第二步获取的用户id,
4、启动V2Ray
=========
在首次安装完成之后,V2Ray不会自动启动,需要手动运行上述启动命令。而在已经运行V2Ray的VPS上再次执行安装脚本,安装脚本会自动停止V2Ray 进程,升级V2Ray程序,然后自动运行V2Ray。在升级过程中,配置文件不会被修改。
启动
systemctl start v2ray
停止
systemctl stop v2ray
重启
systemctl restart v2ray
设置开机自启(这步记得执行一次,不然服务器重启之后v2ray会停掉)
systemctl enable v2ray
到这里为止V2ray已经正常工作
宝塔创建网站
- 使用域名创建网站
- 进入 SSL 配置域名证书
- 进入参数配置
location /r
{
proxy_pass http://127.0.0.1:10000;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_read_timeout 300s;
}
# 上面的 /r 就是在 v2ray config里设置的分流路劲
# 端口默认10000