v2ray进阶版——安装混淆
使用系统:Debian 9 (X64位)
安装Nginx服务器:
用vim更新source list(/etc/apt/sources.list):
deb http://deb.debian.org/debian stretch-backports main
保存退出
运行:apt-get update
1 |
apt-get install -t stretch-backports nginx |
查看nginx版本:nginx -v
确保nginx的版本为1.14或以上
系统已安装防火墙的话,需要打开端口,详见本文:
1 |
ufw allow 'Nginx Full' |
这里表示允许http和https流量通过。
从服务商处取得ip地址,测试Nginx安装成功:
1 |
http://你的ip地址 |
看到截图表明Nginx已经安装成功:
管理Nginx进程的常用语句,以后会用到:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# 停止Nginx进程 systemctl stop nginx # 启动Nginx进程 systemctl start nginx # 重启Nginx进程 systemctl restart nginx # 配置文件修改后,重启配置文件 systemctl reload nginx # 关闭开机自动启动 systemctl disable nginx # 开机自动启动 systemctl enable nginx |
设置一个新网站
Nginx有默认配置的网页(地址:/var/www/html
),即前面截图里的Nginx欢迎页面,网上很多教程直接使用Nginx的默认安装网页和附属配置。但Nginx允许建立多个网站,为了以防将来新建的网站被墙,这里新建一个专门的网页,这样即便这个网页被墙,还可以继续建新的网页。
同样的,申请免费或购买到的域名不要直接启用顶级域名,造成域名浪费,在DNS里添加新子域名,参考本文。这里使用sub.example.com为设置的新子域名,以下涉及到sub.example.com的,全部用自己设置的域名代替。
在/var/www
目录地址下面新建一条路径专门放置新网页:
1 |
mkdir -p /var/www/sub.example.com/html |
对新路径设置权限:
1 |
chown -R $USER:$USER /var/www/sub.example.com/html |
这里使用chmod 755检测设置的权限,无警告即设置成功:
1 |
chmod -R 755 /var/www/sub.example.com |
这里用vim新建一张新网页:
1 |
vim /var/www/sub.example.com/html/index.html |
键入i,进入输入模式,粘贴代码,sub.example.com用自己的域名代替:
1 2 3 4 5 6 7 8 |
<html> <head> <title>Welcome to sub.Example.com!</title> </head> <body> <h1>Success! The sub.example.com server block is working!</h1> </body> </html> |
输入Esc键,输入:wq,保存退出。
在/etc/nginx/sites-available/
新建一个新的设置文件:
1 |
vim /etc/nginx/sites-available/sub.example.com |
复制粘贴以下代码,sub.example.com用自己的域名代替:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
server { listen 80; listen [::]:80; root /var/www/sub.example.com/html; index index.html index.htm index.nginx-debian.html; server_name sub.example.com; location / { try_files $uri $uri/ =404; } } |
连接设置文件和新建的网页:
1 |
ln -s /etc/nginx/sites-available/sub.example.com /etc/nginx/sites-enabled/ |
修改以下文件:
1 |
vim /etc/nginx/nginx.conf |
找到# server_names_hash_bucket_size
删除前面的备注符号#,代码大约如下:
1 2 3 4 5 6 7 |
... http { ... server_names_hash_bucket_size 64; ... } ... |
保存退出。
运行代码:
1 |
nginx -t |
显示如下结果就是没有问题了。
1 2 |
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful |
重启Nginx:
1 |
systemctl restart nginx |
刷新sub.example.com后应该就可以看到新的页面了。
没问题的情况下,去资源网站下载一套网站模板:https://colorlib.com/wp/templates/,用Filezilla将zip包上传到root根目录下,用unzip解压zip包,得到一个新的文件夹,假定这个文件夹的名字为unfold,里面包含了index.html等文件,使用以下代码将unfold文件夹里所有的文件移动到/var/www/sub.example.com/html下:
1 |
mv unfold/* /var/www/sub.example.com/html |
再restart nginx后,刷新页面应该可以看到新生效的网站了。
安装原版v2ray,参考这篇文章,取得安装后的端口号,UUID,AlterID。
用Let’s Encrypt生成SSL证书
首先暂时关闭防火墙,ufw或firewalld,安装的哪个防火墙就用哪个。
1 |
ufw disable |
访问Certbot网站(https://certbot.eff.org/),因为系统是Debian 9,安装的是Nginx,故选择这两项:
网站自动给出代码,按照给出的代码走就可以了:
1 |
apt-get install certbot python-certbot-nginx |
因为是新建的网站,不是Nginx的默认网站,为保险期间,只生成SSL证书,期间会要求提供email地址:
1 |
certbot certonly --nginx |
看到Important Notes就表明生成成功,记下Certificate和PrivateKey的路径地址,即第2行和第4行:
如果报错,查看是否cloudflare等DNS解析的时候打开了CNS(即显示的为橙色的小云),打开的话,需要先关掉。
配置证书自动更新:
1 |
echo "0 0 1 */2 * service nginx stop; certbot renew; service nginx start;" | crontab |
运行这条命令后,如果没有任何信息输出,就表示成功。
验证网站:刷新网站(sub.example.com),网址应该自动加上了https.
重新启动ufw enable,记得将v2ray中设置的端口号在防火墙上开启。
重新配置Nginx
需要设立一个伪装路径,使用这个网站得到一串随机字符串,比如伪装路径 /fZV6HHA,甚至可以增加二级路径/fZV6HHA/hpjiid,斜杠/不能删。
将证书路径更新到Nginx的配置文件中,步骤较复杂,建议用Filezilla下载下来后,使用notepad++进行编辑,以防出错:
1 |
地址 /etc/nginx/sites-available/sub.example.com |
替换为下面的代码,sub.example.com替换为自己设置的域名,伪装路径设为自己的,SSL证书替换为自己生成的证书地址,删除所有带#的备注:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
server { listen 80; listen [::]:80; root /var/www/sub.example.com/html; index index.html index.htm index.nginx-debian.html; server_name sub.example.com; rewrite ^(.*) https://$server_name$1 permanent; location / { try_files $uri $uri/ =404; } } server { location /kjijejio/jfoeij { #伪装路径,需要与v2ray中配置一致 proxy_redirect off; proxy_pass http://127.0.0.1:12345; #与v2ray中端口配置一致 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; # Show real IP in v2ray access.log proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } listen 443 ssl http2; server_name sub.example.com; charset utf-8; # ssl配置 ssl_protocols TLSv1.2 TLSv1.3; # tls 1.3需要确保nginx的版本是1.4以上,故之前多添加了source list ssl_ciphers TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; ssl_ecdh_curve secp384r1; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; ssl_session_tickets off; ssl_certificate /etc/letsencrypt/live/sub.example.com/fullchain.pem; # 改成你的证书地址 ssl_certificate_key /etc/letsencrypt/live/sub.example.com/privkey.pem; # 改成证书密钥文件地址 access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; root /var/www/sub.example.com/html/; location / { index index.html; } } |
运行代码:nginx -t,使配置生效。
重新启动Nginx:systemctl restart nginx
重新修改v2ray配置文件(地址:/etc/v2ray/)
建议先将v2ray停止:systemctl stop v2ray
此步骤较复杂,建议使用Filezilla下载下来进行修改,以防出错,代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
{ "inbounds": [{ "port": xxxxx, "protocol": "vmess", "settings": { "clients": [ { "id": "*******************************", "level": 1, "alterId": 64 } ] }, "streamSettings": { "network": "ws", "wsSettings": { "path": "/******" } } }], "outbounds": [{ "protocol": "freedom", "settings": {} },{ "protocol": "blackhole", "settings": {}, "tag": "blocked" }], "routing": { "rules": [ { "type": "field", "ip": ["geoip:private"], "outboundTag": "blocked" } ] } } |
打x和*号的用自己的代替,port为端口,ID为UUID,Path为伪装路径。
重新上传后,用如下代码验证配置文件:
1 |
/usr/bin/v2ray/v2ray -test -config=/etc/v2ray/config.json |
显示如下结果,即为正确:
1 2 3 4 5 |
V2Ray 4.23.1 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.13 linux/amd64) A unified platform for anti-censorship. 2020/05/27 03:22:47 [Info] v2ray.com/core/common/platform/ctlcmd: <v2ctl message> v2ctl> Read config: /etc/v2ray/config.json Configuration OK. |
重新启动v2ray:systemctl restart v2ray
配置客户端:
Windows:端口设为443,传输协议选择ws,填上设置的伪装域名和伪装路径,底层传输安全选择tls。
整个设置就好了。
参考文档:
安装设置Nginx:https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-18-04
设置v2ray+tls+ws:
1. https://tlanyan.me/v2ray-traffic-mask/
2. https://pincong.rocks/article/15493