Trojan工作原理浅析
注意~!目前不支持CDN
Trojan是一个比较新的翻墙软件,在设计时采用了更适应国情的思路。在穿透GFW时,人们认为强加密和随机混淆可能会欺骗GFW的过滤机制。然而,Trojan实现了这个思路的反面:它模仿了互联网上最常见的HTTPS协议,以诱骗GFW认为它就是HTTPS,从而不被识别。

如图所示,Trojan工作在443端口,并且处理来自外界的HTTPS请求,如果是合法的Trojan请求,那么为该请求提供服务,否则将该流量转交给web服务器Nginx,由Nginx为其提供服务。基于这个工作过程可以知道,Trojan的一切表现均与Nginx一致,不会引入额外特征,从而达到无法识别的效果。当然,为了防止恶意探测,我们需要将80端口的流量全部重定向到443端口,并且服务器只暴露80和443端口,这样可以使得服务器与常见的Web服务器表现一致。
安装web服务器
安装nginx然后创建证书文件夹
yum install nginx
mkdir /usr/local/etc/certfiles把域名绑定到这个vps的ip上
安装acme.sh自动管理CA证书脚本
curl https://get.acme.sh | sh
国内镜像地址
git clone https://gitee.com/neilpang/acme.sh.git
cd acme.sh
./acme.sh --install -m my@example.com申请证书采用http的方式
acme.sh --issue -d <域名> --webroot /usr/local/openresty/nginx/html/tj --force --key-file /usr/local/etc/certfiles/private.key --fullchain-file /usr/local/etc/certfiles/certificate.crt
./acme.sh --issue -d echo.solo90.com --webroot /data/web/echo --key-file /usr/local/openresty/nginx/ssl/echo.solo90.com.key --fullchain-file /usr/local/openresty/nginx/ssl/echo.solo90.com.crt–webroot是指定网站根目录、这个必须跟nginx的配置文件目录一致。后面两个参数是指定ssl证书的位置。
安装成功后此脚本会默认在crotab的定时任务中添加了一条记录

自此之后就不用管理了 、由于 acme 协议和 letsencrypt CA 都在频繁的更新, 因此 acme.sh 也经常更新以保持同步.
手动更新脚本
acme.sh --upgrade
自动更新
acme.sh --upgrade --auto-upgrade
nginx配置文件
server {
listen 80;
server_name y.yanxuw.cn;
# !!! 关键配置:必须优先处理 ACME 验证路径 !!!
location ^~ /.well-known/acme-challenge/ {
# 指定验证文件所在的根目录,必须与 --webroot 参数后的路径一致
alias /data/sites/y.yanxuw.cn/public/.well-known/acme-challenge/;
# 尝试返回请求的文件,如果找不到则返回404
try_files $uri $uri/ =404;
}
# 这是您原有的重定向规则,将所有 HTTP 请求重定向到 HTTPS
location / {
return 301 https://$server_name$request_uri;
}
}
申请泛域名
这里用阿里域名
导入阿里云的Access Key ID和Access Key Secret到环境变量中
export Ali_Key=""
export Ali_Secret=""申请证书
~/.acme.sh/acme.sh --issue --dns dns_ali -d solo90.com -d *.solo90.com
具体操作官方的github里有:github连接传送门
安装Trojan并且配置
sudo bash -c "$(curl -fsSL https://raw.githubusercontent.com/trojan-gfw/trojan-quickstart/master/trojan-quickstart.sh)"
修改配置文件
vim /usr/local/etc/trojan/config.json

下面的其他配置文件不用变
客户端配置
从github上下载https://github.com/trojan-gfw/trojan/releases mac的
服务端和客户端一样就是配置文件不一样

打开start.command 浏览器通过设置代理就可链接
vim /etc/systemd/system/trojan.service
[Unit]
Description=trojan
Documentation=https://trojan-gfw.github.io/trojan/config https://trojan-gfw.github.io/trojan/
After=network.target network-online.target nss-lookup.target mysql.service mariadb.service mysqld.service
[Service]
Type=simple
StandardError=journal
ExecStart="/usr/local/bin/trojan" "/usr/local/etc/trojan/config.json"
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.targetsystemctl daemon-reload
systemctl start trojan
BBR加速
wget --no-check-certificate https://github.com/teddysun/across/raw/master/bbr.sh && chmod +x bbr.sh && ./bbr.sh
sysctl net.ipv4.tcp_available_congestion_control
返回值一般为:net.ipv4.tcp_available_congestion_control = bbr cubic reno
或者为:net.ipv4.tcp_available_congestion_control = reno cubic bbr
秋水一件bbr的脚本文章:https://teddysun.com/489.html
其他bbr脚本
cd /usr/src && wget -N --no-check-certificate "https://raw.githubusercontent.com/chiakge/Linux-NetSpeed/master/tcp.sh" && chmod +x tcp.sh && ./tcp.sh
Trojan的github地址
https://github.com/trojan-gfw/trojan
Trojan-go的安装
trojan-go需要安装go语言1.15.3
项目的github地址:https://github.com/p4gefau1t/trojan-go
systemd的文件编写:
[Unit]
Description=trojan
Documentation=https://trojan-gfw.github.io/trojan/config https://trojan-gfw.github.io/trojan/
After=network.target network-online.target nss-lookup.target mysql.service mariadb.service mysqld.service
[Service]
Type=simple
StandardError=journal
ExecStart=/usr/local/trojan-go/trojan-go -config "/usr/local/trojan-go/config/server.json"
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target共用nginx 443端口的设置
需要nginx中的两个模块,在openresty中是自带的 --with-stream --with-stream_ssl_preread_module

具体配置
1 条评论
这是一篇佳作,无论是从内容、语言还是结构上,都堪称完美。