v2ray websocket(ws)+tls+Nginx分流+BBR(锐速)+cdn+网站(如wordpress)
v2ray·@laosan·
0.000 HBDv2ray websocket(ws)+tls+Nginx分流+BBR(锐速)+cdn+网站(如wordpress)
###### 相关说明 - 已购买vps、域名x.com、域名已解析到vps IP; - 教程vps服务器v2ray端口举例为9000,请自行修改; - vps操作推荐软件:Xshell(win)、zoc(mac); - 全新系统以Debian和Ubuntu为例,centos命令则为yum,如yum update -y; - 利用可视化BT面板:安装web环境、编辑配置相关config; - 全程利用可用的一键脚本,只是在关键的部分采用手动仅为需求而方便设置; - 本文目的在于建立: - 个人网站(如wordpress)+ websocket(ws)+ tls + Nginx分流 + 加速(锐速或BBR)+ CDN; - 所以若旨在安装tcp(http伪装)、mkcp(伪装+tls)、ws+tls,请忽略本文并移步至[v2ray一键脚本][1]; ### `1、更新升级` apt-get update && apt-get upgrade -y ### `2、删除Apache2` > 否则Nginx无法启动 apt-get purge apache2 或 yum erase httpd httpd-tools apr apr-util ### `3、安装BT面板` > 根据不同系统,自行选择相应[一键脚本][2]; > 安装完后,根据提示浏览器打开ip.8888; > 登录面板后台,根据提示,一键安装Nginx、MySQL、PHP、PhpAdmin。 > `选项_安全:放行v2ray端口9000,ssl监听端口443`;这是本教程开放端口,请自行根据自己需要开放自定义端口号。 ### `4、安装v2ray` wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/v2ray.fun/master/install.sh && bash install.sh > 安装完毕,输入v2ray,Enter回车进行脚本操作 > 因为脚本会不断地更新并且一目了然各项功能的选择,所以此文省略具体操作步骤 - 更改主端口9000,默认为1234; - 加密方式自行选择,v2ray服务端根据客户端选择自行选择,默认为none; - 更改传输方式为websocket流量; - #######`不要选择开启tls`,虽方便自动申请ssl,但会在config.json写入tls配置,而Nginx分流实则服务端不需要写入,所以采用下文手动申请ssl; - 按enter回车键退出脚本配置; ### `5、浏览器进入BT面板操作` > 假设已经完成了web环境安装 > - **添加网站 x.com**,自行上传或远程下载安装文件放入x.com文件夹; > - 若是wordpress,第2选择是进入`宝塔一键部署源码`,一键安装wp; > - 若是wp,设置x.com文件夹权限为775 > - 若是从他处迁移过来,解决固定链接问题需要在Nginx添加代码: > - 步骤是在网站——x.com列表右边选择设置——配置文件 > > > location / { > try_files $uri $uri/ /index.php?q=$uri&$args; > } ### `6、申请SSL` > 进入xshell或zoc等vps操作软件; > 过程若出现缺少依赖而错误,请根据提示自行安装依赖包 > 自行把域名x.com修改为自己的域名 安装 acme.sh curl https://get.acme.sh | sh source ~/.bashrc apt-get -y install netcat > `利用BT面板,停止Nginx运行` 生成证书 ~/.acme.sh/acme.sh --issue -d x.com --standalone -k ec-256 安装证书和密钥 ~/.acme.sh/acme.sh --installcert -d x.com --fullchainpath /etc/v2ray/v2ray.crt --keypath /etc/v2ray/v2ray.key > `注意修改上述x.com为自己域名` ### `7、添加v2ray的ws_path路径`,编辑/etc/v2ray/config.json, "wsSettings": { "headers": { "host": "x.com" }, "path": "/ws", # 在单引号 ""里添加/ws ### `8a、配置Nginx`:透过浏览器登录BT面板 在配置文件最后一行添加如下: server { listen 443 ssl; #若要透过其他转发https给v2ray服务端口9000,请自行修改443为其他监听端口 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 x.com; #修改自己域名 location /ws { #/ws为v2ray路径,随便填写比如/v2ray/ proxy_redirect off; proxy_pass http://127.0.0.1:9000; #修改自己v2ray服务端口 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $http_host; } } > A、如果利用bt面板成功申请ssl,可忽略步骤停止nginx运行;并在Nginx里最后一个 `}`前面只需要填入: location /ws { #/ws为v2ray路径,随便填写比如/v2ray/ proxy_redirect off; proxy_pass http://127.0.0.1:9000; #修改自己v2ray服务端口 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $http_host; } > B、如果利用v2ray一键脚本安装tls,打开/etc/v2ray/config.json,记录配置文件tls证书位置,替换上文Nginx代码中的ssl证书的两个位置 ssl_certificate /etc/v2ray/v2ray.crt; #修改证书路径 ssl_certificate_key /etc/v2ray/v2ray.key; #修改证书路径 或者执行下述代码,这样就不用修改 Nginx中的证书位置: ~/.acme.sh/acme.sh --installcert -d x.com --fullchainpath /etc/v2ray/v2ray.crt --keypath /etc/v2ray/v2ray.key > 完成上述后,`删除`/etc/v2ray/config.json中tls相关设置,恢复如下: "streamSettings": { "tlsSettings": {}, "security": "" } > `注意修改上述x.com为自己域名` ### `8b、分流可选方案二`,不透过Nginx监听ssl,而是透过caddy - nginx根据上述三种不同ssl申请方式,配置文件代码必须具有: server { listen 443 ssl; #若要透过其他端口转发https给v2ray服务端口9000,请自行修改443为其他监听端口 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; } - **安装caddy** wget --no-check-certificate https://softs.fun/Bash/caddy_install.sh && chmod +x caddy_install.sh && bash caddy_install.sh install http.filemanager - **配置caddy** > 新建文件:/usr/local/caddy/`Caddyfile`,填入代码 caddy x.com #修改为自己的域名 { log ./caddy.log proxy /ws locaohost:9000 { #修改为自己的v2ray服务端口,和v2ray路径 websocket header_upstream -Origin } } ### `9、完成上述所有操作后,重启服务器 或 重启以下服务`,使配置生效** ##### v2ray重启 service v2ray restart ##### 重启nginx:BT面板 ##### 重启caddy service caddy restart ##### `记得在BT面板的安全选项开放上述端口,教程里是443和9000` ### `10、加速安装` #### `10a、kvm内核` #### 锐速 - 需要相应内核支持,若不支持请更换内核,本人推荐Debian7,内核一定合适 - [91yun锐速][3] wget -N --no-check-certificate https://github.com/91yun/serverspeeder/raw/master/serverspeeder.sh && bash serverspeeder.sh 或[逗比根据地一键脚本:包含锐速、bbr][4] wget -N --no-check-certificate https://softs.fun/Bash/ssrmu.sh && chmod +x ssrmu.sh && bash ssrmu.sh #### BBR - 开通正常的BBR:[秋水逸冰 » 一键安装最新内核并开启 BBR 脚本][5] wget --no-check-certificate https://github.com/teddysun/across/raw/master/bbr.sh chmod +x bbr.sh ./bbr.sh - 魔改BBR:https://moeclub.org/2017/06/24/278/ ###### 开启BBR wget --no-check-certificate -qO 'BBR.sh' 'https://moeclub.org/attachment/LinuxShell/BBR.sh' && chmod a+x BBR.sh && bash BBR.sh -f > 注意:执行此命令会自动重启 ###### 安装 wget --no-check-certificate -qO 'BBR_POWERED.sh' 'https://moeclub.org/attachment/LinuxShell/BBR_POWERED.sh' && chmod a+x BBR_POWERED.sh && bash BBR_POWERED.sh #### `10b、openvz内核` - [扩软博客的OpenVZ 平台 Google BBR 一键安装脚本][6] wget https://raw.githubusercontent.com/kuoruan/shell-scripts/master/ovz-bbr/ovz-bbr-installer.sh chmod +x ovz-bbr-installer.sh ./ovz-bbr-installer.sh > 分流需要添加两个端口:监听端口443和v2ray服务端口9000,修改/usr/local/haproxy-lkl/etc/port-rules,保存 0.0.0.0 443 0.0.0.0 443 0.0.0.0 9000 0.0.0.0 9000 > 重启服务 service haproxy-lkl restart - [lkl_Rinetd][7](我自己ovz采用这个速度杠杠的),@phuslu的一键脚本 curl https://raw.githubusercontent.com/linhua55/lkl_study/master/get-rinetd.sh | bash > 多端口添加修改地址:/etc/rinetd-bbr.conf > 查看ip规则 iptables -t raw -nL ### `11、配置cdn` - 免费的当属CloudFlare,但大陆地区支持未必理想; - 不赞成先cdn,因为可能会影响申请ssl,所以建议以上都完毕后再更换为cdn服务; - 若是CloudFlare,那么crypto选项里,SSL,选择Full(strict),然后可全部勾选当页选项。 ### 如果是wordpress,配置ssl后如果出现部分页面https不安全现象,请安装插件 - [SSL 不安全内容修复器][8]:根据检测自动修复ssl; - 推荐安装免费快取外挂[Breeze][9]:加速网站打开; ### `12、客户端设置` - 端口:443(非9000) - address:x.com(非ip) - websocket(ws)path(路径):/ws - 勾选tls 参考文献: - https://www.bt.cn/bbs/thread-1186-1-1.html - https://www.91yun.co/archives/683 - https://doub.io/ss-jc60/ - https://teddysun.com/489.html - https://blog.kuoruan.com/116.html - https://toutyrater.github.io/advanced/websocket.html - https://github.com/linhua55/lkl_study - https://github.com/FunctionClub/v2ray.fun [1]: https://github.com/tracyone/v2ray.fun [2]: https://www.bt.cn/bbs/thread-1186-1-1.html [3]: https://www.91yun.co/archives/683 [4]: https://doub.io/ss-jc60/ [5]: https://teddysun.com/489.html [6]: https://blog.kuoruan.com/116.html [7]: https://github.com/linhua55/lkl_study [8]: https://cn.wordpress.org/plugins/ssl-insecure-content-fixer/ [9]: https://tw.wordpress.org/plugins/breeze/