Last active
March 27, 2023 14:57
-
-
Save ComeBey/1c57eea5121a21d68945a74dfc3b0a69 to your computer and use it in GitHub Desktop.
V2Ray+WebSocket+TLS+Nginx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
centos7系统环境搭建(温馨提示:请使用centos7系统搭建,如果学习能力强可以Google搜索Debian或其他系统搭建方法,只是部分代码不一样而已)(V2Ray+WebSocket+TLS+Nginx)前几期视频分别提到过 TLS 和 WebSocket 的配置方法,而本文搭配 Web 服务并同时实现 TLS | |
和 WebSocket浏览器域名访问自动跳转https有简单前端网页。关于 Web 的软件官方给出Nginx,Caddy 和 Apache 三个例子,三选一即可 | |
本期只讲Nginx,因为以后视频会用到Nginx | |
一.安装v2ray官方脚本和BBR加速 | |
第一步 V2RAY官方脚本搭建 | |
(1)更新服务器 yum -y update(部分系统提示NO packages marked for update则无需更新) | |
(2)设置硬件时钟调整为与本地时钟一致 | |
timedatectl set-local-rtc 1 | |
设置时区为上海 | |
timedatectl set-timezone Asia/Shanghai | |
(3)Debian系统同步时间如下: | |
date -R 查看时间 | |
rm -rf /etc/localtime | |
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime | |
第二部 安装bbr(可选择安装了v2ray以后在安装) | |
centos7系统 | |
yum -y install wget | |
wget "https://github.com/chiakge/Linux-NetSpeed/raw/master/tcp.sh" && chmod +x tcp.sh && ./tcp.sh | |
debian系统 请确定服务器已经按照了wget 如没有按照请先执行这条代码 apt-get install wget | |
wget --no-check-certificate -O tcp.sh https://github.com/cx9208/Linux-NetSpeed/raw/master/tcp.sh && chmod +x tcp.sh && ./tcp.sh | |
第三步 安装v2ray官方代码 | |
bash <(curl -L -s https://install.direct/go.sh) | |
安装成功后执行 vim /etc/v2ray/config.json 长按键盘D键删所有代码,在输入键盘Ins键或者i键进入可编辑状态,复制以下代码 同时按键盘shift+:输入wq保存退出 | |
#复制以下代码 | |
{ | |
"log" : { | |
"access": "/var/log/v2ray/access.log", | |
"error": "/var/log/v2ray/error.log", | |
"loglevel": "warning" | |
}, | |
"inbound": { | |
"port": 9000, //重点(此端口与nginx配置保持一致) | |
"listen": "127.0.0.1", //重点(此端口与nginx配置保持一致) | |
"protocol": "vmess", | |
"settings": { | |
"clients": [ | |
{ | |
"id": "eb950add-608e-409d-937f-e797324387093z", //你的UUID,可更改需与客户端保持一致 | |
"level": 1, | |
"alterId": 64 //此ID也需与客户端保持一致(不要设置超过100以上可自定义) | |
} | |
] | |
}, | |
"streamSettings":{ | |
"network": "ws", //可设置tcp等 | |
"wsSettings": { | |
"path": "/v2ray" //与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" | |
} | |
] | |
} | |
} | |
} | |
service v2ray start|stop|status|reload|restart|force-reload 控制 V2Ray 的运行 | |
打开 80(HTTP)和 443(HTTPS)端口(如果看过我前几期视频,确定防火墙规则设置好了,谷歌云可以忽略。其他品牌服务器请确认已经开启了80和443端口如果没有可尝试下面代码操作或者服务器网页端 | |
开启http80端口和https 443端口) | |
通过下面的命令来打开这两个端口: | |
sudo firewall-cmd --permanent --zone=public --add-service=http | |
sudo firewall-cmd --permanent --zone=public --add-service=https | |
sudo firewall-cmd --reload | |
第四步.安装NGINX | |
(1)sudo yum install epel-release //安装 EPEL 仓库(谷歌云忽略此步骤,如果你是使用其他品牌vps服务器如果没有安装EPEL请先安装) | |
(2)sudo yum install nginx //安装Nginx如果你使用谷歌云请执行第(2)步骤,无需安装(1)步骤 【 yum remove nginx如果想删除nginx卸载命令 】 | |
(3)sudo systemctl enable nginx.service //设置开机启动Nginx | |
(4)sudo systemctl start nginx.service //启动Nginx服务 | |
调试代码如下: | |
sudo systemctl start nginx.service //开启 Nginx | |
sudo systemctl stop nginx.service //停止 Nginx | |
sudo systemctl status -l nginx.service //查看 Nginx运行状态 | |
sudo systemctl restart nginx.service //重新启动 Nginx | |
sudo systemctl disable nginx.service //取消开机启动 Nginx | |
sudo systemctl reload nginx.service //重载Nginx (如更改Nginx配置需要重新载入数据) | |
sudo systemctl enable nginx.service //开机启动 | |
通过以上方式安装的 Nginx,所有相关的配置文件都在 /etc/nginx/ 目录中 | |
Nginx 的主配置文件是 /etc/nginx/nginx.conf | |
Nginx 日志文件(access.log 和 error.log )位于 /var/log/nginx/ 目录中。 | |
如果在设置完成之后不能成功使用,可能是由于 SElinux 机制(如果你是 CentOS 7 的用户请特别留意SElinux 这一机制)阻止了 Nginx 转发向内网的数据 | |
如果是这样的话,在V2Ray的日志里不会有访问信息,在 Nginx 的日志里会出现大量的 "Permission Denied" 字段 | |
要解决这一问题需要在终端下键入以下命令: | |
setsebool -P httpd_can_network_connect 1 //重要安装 centos系统安装 debian系统忽略 | |
验证 Nginx 是否成功启动,可以在浏览器中打开 http://YOUR_IP 注意:打开则显示centos网页 但是提示不安全网站没开启ssl加密https | |
二.配置安装证书如果你已经有其他证书可忽略,只需在Nginx 中指定 证书和密钥路径。申请证书方法太多可通过安装acme.sh工具生成证书或其他方法生成证书,可Google搜索。 | |
1.安装acem.sh证书生成工具,以下提供3种方法安装,选其中任意一种方法安装证书工具 (温馨提示:自动升级acme.sh在root下输入 acme.sh upgrade) | |
(1)curl https://get.acme.sh | sh // 如提示安装失败 请先安装curl 输入 yum -y install curl | |
(2)wget -O - https://get.acme.sh | sh //如提示安装失败请(先安装wget)输入 yum -y install wget 已经安装了忽略 | |
(3)git clone https://github.com/acmesh-official/acme.sh.git // 如提示安装失败 先安装git 已经安装了的忽略 输入 yum install git | |
cd ./acme.sh | |
./acme.sh --install | |
通过以上代码安装acme.sh提示红色抱错 你可以按实际相关情况而定安装依赖 比如安装socat 或者 netcat | |
centos7 yum install socat | |
centos7 yum isntall netcat | |
debian apt-get install openssl cron socat curl | |
debian apt-get -y install netcat | |
(4)安装成功后执行 source ~/.bashrc 以确保脚本所设置的命令别名生效 | |
2.生成证书 路径为/root/.acme.sh文件下 安装好后可自行查看 | |
温馨提示:通过acme.sh生成证书有多种方法: | |
例如---自动DNS API集成 如:cloudflare DNS API 令牌 和 使用全局API密钥 acme.sh支持大多数dns生成证书 | |
例如---使用DNS手动模式,等多种其他安装方法,如果你是个好学的人可Google | |
生成证书如下:本期视频只用指定端口 生成证书 (一般用单域名足以,毕竟是翻墙用无需搞那么多花里胡哨的多域) | |
sudo ~/.acme.sh/acme.sh --issue -d 域名 --standalone -k ec-256 (通过侦听80端口申请证书,如果端口被占用请使用443端口请确保这些端口都打开了) | |
sudo ~/.acme.sh/acme.sh --issue -d 域名 --standalone --httpport 端口(如果您80在反向代理或负载均衡器后面使用非标准端口,则可以--httpport用来指定端口) | |
sudo ~/.acme.sh/acme.sh --issue -d 域名 --alpn -k ec-256 (侦听443端口以颁发证书,请确保443端口开启) | |
sudo ~/.acme.sh/acme.sh --issue -d 域名 --alpn --tlsport 端口 (如果您443在反向代理或负载均衡器后面使用非标准端口,则可以--tlsport用来指定端口) | |
-k 表示密钥长度,后面的值可以是 ec-256 、ec-384、2048、3072、4096、8192,带有 ec 表示生成的是 ECC 证书,没有则是 RSA 证书。在安全性上 256 位的 ECC 证书等同于 3072 位的 RSA 证书 | |
3.安装证书和密钥到指定路径 /etc/v2ray (路径可自定义) | |
(1) ecc 安装代码 sudo ~/.acme.sh/acme.sh --installcert -d 域名 --fullchainpath /etc/v2ray/v2ray.crt --keypath /etc/v2ray/v2ray.key --ecc | |
(2) rsa 安装代码 sudo ~/.acme.sh/acme.sh --installcert -d 域名 --fullchainpath /etc/v2ray/v2ray.crt --keypath /etc/v2ray/v2ray.key | |
三.配置NGINX *.conf | |
(1)vim /etc/nginx/nginx.conf //编辑配置文件:长按键盘上D键删除所有配置信息,再按键盘Ins键进入编辑模式复制如下代码黏贴到配置文件中。 | |
同时按键盘上shift+:键,在输入wq保存退出 | |
#--复制代码以下代码------------------------------------------------------------------------------------------------------------- | |
user nginx; | |
worker_processes auto; | |
error_log /var/log/nginx/error.log; | |
pid /run/nginx.pid; | |
include /usr/share/nginx/modules/*.conf; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
access_log /var/log/nginx/access.log main; | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay on; | |
keepalive_timeout 65; | |
types_hash_max_size 2048; | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
include /etc/nginx/conf.d/*.conf; | |
server { | |
listen 80; | |
server_name 域名; | |
rewrite ^/(.*) https://域名$1 permanent; | |
} | |
server #关键代码 | |
{ | |
# SSL configuration | |
listen 443 ssl http2 default_server; | |
listen [::]:443 ssl http2 default_server; | |
ssl_certificate /路径/*.pem; #你的ssl证书*.crt 或者 *.pem都可以 | |
ssl_certificate_key /路径/*.key; #你的ssl key | |
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+ECDSA+AES128:EECDH+aRSA+AES128:RSA+AES128:EECDH+ECDSA+AES256:EECDH+aRSA+AES256:RSA+AES256:EECDH+ECDSA+3DES:EECDH+aRSA+3DES:RSA+3DES:!MD5; | |
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; | |
root /usr/share/nginx/html; #网页路径 | |
server_name 域名; #你的服务器域名 | |
location /ray { #/ray 路径需要和v2ray服务器端和客户端保持一致 可自定义名字 | |
proxy_redirect off; | |
proxy_pass http://127.0.0.1:端口; #此IP地址和端口需要和v2ray服务器端配置保持一致, | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
proxy_set_header Host $http_host; | |
} | |
} | |
#请勿随意转载,如需转载请注明出处 | |
#https://gist.github.com/ComeBey/1c57eea5121a21d68945a74dfc3b0a69/edit | |
#我们的电报群https://t.me/RootInstitute | |
} | |
#---------------代码复制到这里-------------------------------------------------------------------------------------------------- | |
(2)修改 Nginx 配置后,请务必重新加载配置 输入 sudo systemctl reload nginx.service #必须这样操作 | |
查询是否开启ssl 打开网站https://myssl.com/ssl.html查看端口输入443 或者 打开https://www.ssllabs.com/ssltest/index.html 查询 也可以google搜索关键字ssl查询很多网站可以查询 | |
是不是评分是否到达A级别 | |
通过在浏览器输入自己域名查询是否发现网站加了一把锁🔒开启了https, 且网站域名ssl评分到达A 如果是,恭喜你搭建成功.如果你已经学会了那么接下来的课程会越来越有意思, | |
但也会随着课程越来越难。加油~各位老铁! | |
调试代码如下: Nginx调试也可以不需要代码后面添加 nginx.service 也可以不需要 .service 前提必须先sudo systemctl start nginx.service
和sudo systemctl enable nginx.service 然后在通过下面代码也可以调试区别在于多了一个 .servcie
sudo systemctl start nginx //开启 Nginx
sudo systemctl stop nginx //停止 Nginx
sudo systemctl status -l nginx //查看 Nginx运行状态
sudo systemctl restart nginx //重新启动 Nginx
sudo systemctl disable nginx //取消开机启动 Nginx
sudo systemctl reload nginx //重载Nginx (如更改Nginx配置需要重新载入数据)
sudo systemctl enable nginx //开机启动
ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
(RSA套件)
EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+ECDSA+AES128:EECDH+aRSA+AES128:RSA+AES128:EECDH+ECDSA+AES256:EECDH+aRSA+AES256:RSA+AES256:EECDH+ECDSA+3DES:EECDH+aRSA+3DES:RSA+3DES:!MD5;
(Ecc套件)
想重新装时发现YouTube视频没了,废了老大劲才从原有VPS文件里面找到这里,收藏保存了!
YouTube搜索comebey关键字频道
xialei-ua5 <[email protected]>于2020年9月13日 周日00:41写道:
… ***@***.**** commented on this gist.
------------------------------
想重新装时发现YouTube视频没了,废了老大劲才从原有VPS文件里面找到这里,收藏保存了!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/1c57eea5121a21d68945a74dfc3b0a69#gistcomment-3451676>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALEU2XXNF3XKZTQRVCQ7VWLSFOQFBANCNFSM4NFVSAXA>
.
www.rootfw.com
Hasan W <[email protected]>于2020年9月13日 周日00:46写道:
… YouTube搜索comebey关键字频道
xialei-ua5 ***@***.***>于2020年9月13日 周日00:41写道:
> ***@***.**** commented on this gist.
> ------------------------------
>
>
>
> 想重新装时发现YouTube视频没了,废了老大劲才从原有VPS文件里面找到这里,收藏保存了!
>
>
>
>
>
>
> —
> You are receiving this because you authored the thread.
>
>
> Reply to this email directly, view it on GitHub
> <https://gist.github.com/1c57eea5121a21d68945a74dfc3b0a69#gistcomment-3451676>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ALEU2XXNF3XKZTQRVCQ7VWLSFOQFBANCNFSM4NFVSAXA>
> .
>
>
>
>
感谢!已订阅收藏!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
温馨提示:通过acme.sh工具生成证书请使用443端口 代码如下:
sudo ~/.acme.sh/acme.sh --issue -d 域名 --alpn -k ec-256
(侦听443端口以颁发证书,请确保443端口开启 按文章流畅操作80端口生成证书时会提示端口占用,当然如果你想简单点可以通过也有的证书密钥直接复制拷贝到服务器指定路径下,在配置nginx