Trojan + Nginx 搭建代理手记 您所在的位置:网站首页 阿里云bbr Trojan + Nginx 搭建代理手记

Trojan + Nginx 搭建代理手记

2024-03-17 13:16| 来源: 网络整理| 查看: 265

Trojan 是一种无法识别的可绕过GFW的机制。配合 Nginx可以做到伪装域名流量,降低被GFW检测的风险。本手记面向已拥有一定经验的操作人员。

部署环境:

腾讯云 CentOS 8.2

准备工作:

已解析到服务器的域名 绑定到域名的SSL证书 方案分析

Trojan 默认监控443端口(伪装https),其能识别访问该端口的正常流量和代理流量,将正常流量转发到Nginx的80端口处理,代理流量走代理。

Nginx 只负责80端口,网页托管在该端口。

29190b3d01994938647c5cfab418d6f4.png

缺点:网站https访问会经过一次转发,访问速度可能下降

优点:便于部署,技术力低,时间成本低,代理速度更快

配置文件

/etc/nginx/conf.d/default.conf

12345678server { listen 0.0.0.0:80; server_name domian; location / { root /usr/share/www; index index.html; }}

/usr/local/etc/trojan/config.json(部分)

123456789101112{ "password": [ "password" ], ... "ssl": { "cert": "/pathTo/domian.crt", "key": "/pathTo/domian.key", ... } ...} 流程手记Trojan安装与指令

trojan官方提供的一键部署脚本。

1bash -c "$(curl -fsSL https://raw.githubusercontent.com/trojan-gfw/trojan-quickstart/master/trojan-quickstart.sh)"

Trojan相关命令

查看trojan版本

1trojan -v

查看trojan运行状态

1ss -lp | grep trojan

操作trojan服务

123systemctl stop trojansystemctl start trojansystemctl restart trojan Nginx安装与指令

CentOS 8 預設 AppStream 軟體倉庫 (repo,repository) 提供的 NGINX 版本為 1.14.1,本章透過 NGINX 官方軟體倉庫,即可使用 yum/dnf 指令來安裝 NGINX 穩定或最新版本,参考nginx官方文档。

安裝能夠選擇指定 yum 的套件:

1yum install yum-utils -y

设置yum安装nginx的仓库源

1vim /etc/yum.repos.d/nginx.repo 123456789101112131415[nginx-stable]name=nginx stable repobaseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=1enabled=1gpgkey=https://nginx.org/keys/nginx_signing.keymodule_hotfixes=true[nginx-mainline]name=nginx mainline repobaseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/gpgcheck=1enabled=0gpgkey=https://nginx.org/keys/nginx_signing.keymodule_hotfixes=true

通过以下命令,修改--enable参数更改需要安装的nginx版本

1yum-config-manager --enable nginx-mainline nginx-stable: 稳定版 nginx-mainline: 最新版

安装nginx

1yum install nginx

查看nginx版本信息

1yum info nginx 12345678910111213141516Last metadata expiration check: 0:00:48 ago on Fri 11 Jun 2021 04:08:38 PM CST.Installed PackagesName : nginxEpoch : 1Version : 1.21.0Release : 1.el8.ngxArchitecture : x86_64Size : 2.8 MSource : nginx-1.21.0-1.el8.ngx.src.rpmRepository : @SystemFrom repo : nginx-mainlineSummary : High performance web serverURL : https://nginx.org/License : 2-clause BSD-like licenseDescription : nginx [engine x] is an HTTP and reverse proxy server, as well as : a mail proxy server.

查看nginx版本

1nginx -v 1nginx version: nginx/1.21.0

Nginx命令参数

优雅退出nginx服务

1nginx -s quit

退出nginx服务

1nginx -s stop

重启nginx服务

1nginx -s reload

检验配置文件语法

1nginx -t

载入配置文件

1nginx -c /etc/nginx/nginx.conf BBR加速代理

BBR 是 Google 提出的一种新型拥塞控制算法,可以使 Linux 服务器显著地提高吞吐量和减少 TCP 连接的延迟。

开启 BBR 要求 4.10 以上版本 Linux 内核,可使用如下命令查看当前内核版本

1uname -r

开启BBR

使用官方

123echo 'net.core.default_qdisc=fq' >> /etc/sysctl.conf echo 'net.ipv4.tcp_congestion_control=bbr' >> /etc/sysctl.conf sysctl -p

使用自动脚本

1curl -O https://raw.githubusercontent.com/teddysun/across/master/bbr.sh && sh bbr.sh

验证BBR

查看可以用的拥塞控制算法

1sysctl net.ipv4.tcp_available_congestion_control

查看现在使用的拥塞控制算法

1sysctl net.ipv4.tcp_congestion_control

检查BBR是否正常运行

1lsmod | grep tcp_bbr


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有