Linux宝塔面板 + Nginx服务环境下,v2ray配置双模式(Websocket 或 Websocket + TLS)

文章小编 219 0

第一步

先安装宝塔面板,并且装好Nginx,详情安装方法参考官网:https://www.bt.cn/bbs/thread-79460-1-1.html

第二步

使用一键安装脚本v2ray,在终端中运行以下命令,根据每一步提示逐步安装完成。

bash <(curl -s -L https://git.io/v2ray.sh)

传输协议选择Websocket,其他按默认一路回车即可,下一步会重新调整配置文件,这里配置的会失效。


脚本安装截图

参考文档:https://github.com/233boy/v2ray/wiki/V2Ray%E4%B8%80%E9%94%AE%E5%AE%89%E8%A3%85%E8%84%9A%E6%9C%AC

第三步

在宝塔面板的文件管理,编辑v2ray配置文件,路径:/etc/v2ray/config.json ,粘贴以下配置:

{
    "log": {
        "access": "/var/log/v2ray/access.log",
        "error": "/var/log/v2ray/error.log",
        "loglevel": "warning"
    },
    "inbounds": [
        {
            "port": 你的端口,
            "protocol": "vmess",
            "settings": {
                "clients": [
                    {
                        "id": "你的ID",
                        "level": 1,
                        "alterId": 0
                    }
                ]
            },
            "streamSettings": {
                "network": "ws",
                "wsSettings": {
                    "path": "/ws"
                }
            },
            "sniffing": {
                "enabled": true,
                "destOverride": [
                    "http",
                    "tls"
                ]
            }
        }
        //include_ss
        //include_socks
        //include_mtproto
        //include_in_config
        //
    ],
    "outbounds": [
        {
            "protocol": "freedom",
            "settings": {}
        },
        {
            "protocol": "blackhole",
            "settings": {},
            "tag": "blocked"
        },
        {
            "protocol": "mtproto",
            "settings": {},
            "tag": "tg-out"
        }
        //include_out_config
        //
    ],
    "dns": {
        "servers": [
            "https+local://8.8.8.8/dns-query",
            "8.8.8.8",
            "1.1.1.1",
            "localhost"
        ]
    },
    "routing": {
        "domainStrategy": "IPOnDemand",
        "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"
            },
            {
                "type": "field",
                "inboundTag": ["tg-in"],
                "outboundTag": "tg-out"
            }
            ,
            {
                "type": "field",
                "domain": [
                    "domain:epochtimes.com",
                    "domain:epochtimes.com.tw",
                    "domain:epochtimes.fr",
                    "domain:epochtimes.de",
                    "domain:epochtimes.jp",
                    "domain:epochtimes.ru",
                    "domain:epochtimes.co.il",
                    "domain:epochtimes.co.kr",
                    "domain:epochtimes-romania.com",
                    "domain:erabaru.net",
                    "domain:lagranepoca.com",
                    "domain:theepochtimes.com",
                    "domain:ntdtv.com",
                    "domain:ntd.tv",
                    "domain:ntdtv-dc.com",
                    "domain:ntdtv.com.tw",
                    "domain:minghui.org",
                    "domain:renminbao.com",
                    "domain:dafahao.com",
                    "domain:dongtaiwang.com",
                    "domain:falundafa.org",
                    "domain:wujieliulan.com",
                    "domain:ninecommentaries.com",
                    "domain:shenyun.com"
                ],
                "outboundTag": "blocked"
            }            ,
                {
                    "type": "field",
                    "protocol": [
                        "bittorrent"
                    ],
                    "outboundTag": "blocked"
                }
            //include_ban_ad
            //include_rules
            //
        ]
    },
    "transport": {
        "kcpSettings": {
            "uplinkCapacity": 100,
            "downlinkCapacity": 100,
            "congestion": true
        }
    }
}

可个性化定义的配置项有:

  • "port": 端口号 // v2ray端口号

  • "id": "用户ID" // 用户id

  • "alterId": 0 // 额外id

  • "path": "/ws" // 路径

接着重启v2ray服务,在终端运行以下命令

v2ray restart

然后在宝塔面板 > 安全,把上述设置的v2ray端口号(你的端口号)添加放行,如果云服务器的提供商自带有安全策略防火墙,则还需添加白名单来放行,其中要包含v2ray端口号(你的端口号)以及443端口。


如未放行443,则需加上


第四步

宝塔中添加网站,绑定在Cloudflare配置好的域名,注意需在CloudflareSSL/TLS改为灵活



宝塔中的网站配置SSL证书开启强制HTTPS,然后在站点配置文件最下面加入配置代码

此处的路径、v2ray端口必须和第二步配置的保持一样
    #/ws为v2ray路径
    location /ws
    {
          proxy_redirect off;
          proxy_pass http://127.0.0.1:8989; #你的v2ray端口
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
          proxy_set_header Host $http_host;
    }

                            此时的服务端已配置完成

v2rayN客户端配置

添加 Websocket 模式服务端配置

此时已经可以在v2rayN客户端中配置好服务器,属于Websocket模式,不经过Cloudflare,直连方式,速度较快,根据第三步中配置的个性化相关,添加Vmess服务器,配置如图:

验证下是否可用

添加 Websocket + TLS 模式服务端配置

验证下是否可用

可以切换任意模式互不影响

至此搞定~

附上快速管理 V2Ray 命令

v2ray info 查看 V2Ray 配置信息
v2ray config 修改 V2Ray 配置
v2ray link 生成 V2Ray 配置文件链接
v2ray infolink 生成 V2Ray 配置信息链接
v2ray qr 生成 V2Ray 配置二维码链接
v2ray ss 修改 Shadowsocks 配置
v2ray ssinfo 查看 Shadowsocks 配置信息
v2ray ssqr 生成 Shadowsocks 配置二维码链接
v2ray status 查看 V2Ray 运行状态
v2ray start 启动 V2Ray
v2ray stop 停止 V2Ray
v2ray restart 重启 V2Ray
v2ray log 查看 V2Ray 运行日志
v2ray update 更新 V2Ray
v2ray update.sh 更新 V2Ray 管理脚本
v2ray uninstall 卸载 V2Ray



标签: Linux宝塔面板 Nginx服务环境下 v2ray配置双模式 Websocket TLS)

抱歉,评论功能暂时关闭!