去评论
屠城辅助网

当前最强后端 XrayR部署Nginx+Trojan

云曦☆初恋
2022/07/08 00:27:57
写在前面

XrayR为GIthub上开源项目,项目地址

XrayR-project/XrayR: A Xray backend framework that can easily support many panels. 一个基于Xray的后端框架,支持V2ay,Trojan,Shadowsocks协议,极易扩展,支持多面板对接 (github.com)

特点

永久开源且免费。
支持V2ray,Trojan, Shadowsocks多种协议。
支持Vless和XTLS等新特性。
支持单实例对接多面板、多节点,无需重复启动。
支持限制在线IP
支持节点端口级别、用户级别限速。
配置简单明了。
修改配置自动重启实例。
方便编译和升级,可以快速更新核心版本, 支持Xray-core新特性。

centOS7为例

首先 CentOS 禁用 SELinux

  1. sed -i 's/enforcing/disabled/g' /etc/selinux/config /etc/selinux/config
  2. #修改后要重启
  3. reboot


安装加速

推荐使用BBR2或BBRPlus

  1. yum install wget
  2. wget -N --no-check-certificate "https://github.000060000.xyz/tcp.sh" && chmod +x tcp.sh && ./tcp.sh


关闭防火墙

  1. systemctl stop firewalld.service  \\关闭

  2. systemctl disable firewalld.service  \\开机禁自启


部署Nginx并安装stream模块

  1. yum update
  2. yum -y install epel-release
  3. yum install -y nginx
  4. yum install nginx-mod-stream


Ubuntu/Debian:

  1. apt update
  2. apt install nginx


检测Nginx状态,是否安装成功

  1. systemctl start nginx
  2. systemctl status nginx.service


添加nginx开机自启

  1. systemctl enable nginx.service


安装失败自行排查原因,或手动编译Nginx 1.21.0

cerbot部署证书

  1. yum install snapd
  2. systemctl enable --now snapd.socket
  3. ln -s /var/lib/snapd/snap /snap
  4. snap install snap-store

  1. snap install core;  snap refresh core
  2. snap install --classic certbot
  3. ln -s /snap/bin/certbot /usr/bin/certbot
  4. certbot --nginx


PS:cerbot教程随官方文档更新,视频为老版本教程,两者同样适用,如果执行certbot –nginx 后 提示

Could not automatically find a matching server block for 域名. Set the `server_name` directive to use the Nginx installer

在/etc/nginx/nginx.conf 配置文件中 server_name 添加你的域名

示例:

  1. server_name aaa.con


重载nginx;重新部署证书

  1. systemctl restart nginx.service
  2. certbot --nginx


Nginx配置

修改/etc/nginx/nginx.conf配置文件

  1. stream {
  2.     server {
  3.         listen              443 ssl;                    # 设置监听端口为443

  4.         ssl_protocols       TLSv1.2 TLSv1.3;      # 设置使用的SSL协议版本

  5.         ssl_certificate /etc/nginx/ssl/xx.com.pem; # 证书地址
  6.         ssl_certificate_key /etc/nginx/ssl/xx.com.key; # 秘钥地址
  7.         ssl_session_cache   shared:SSL:10m;             # SSL TCP会话缓存设置共享内存区域名为
  8.                                                         # SSL,区域大小为10MB
  9.         ssl_session_timeout 10m;                        # SSL TCP会话缓存超时时间为10分钟
  10.         proxy_protocol    on; # 开启proxy_protocol获取真实ip
  11.         proxy_pass        127.0.0.1:1234; # 后端Trojan监听端口
  12.     }
  13. }


请将上方代码添加到http与events中间一行

/etc/nginx/nginx.conf配置文件参考:

  1. events {
  2.     worker_connections 768;
  3.     # multi_accept on;
  4. }

  5. stream {
  6.     server {
  7.         listen              443 ssl;                    # 设置监听端口为443

  8.         ssl_protocols       TLSv1.2 TLSv1.3;      # 设置使用的SSL协议版本

  9.         ssl_certificate /etc/nginx/ssl/xx.com.pem; # 证书地址
  10.         ssl_certificate_key /etc/nginx/ssl/xx.com.key; # 秘钥地址
  11.         ssl_session_cache   shared:SSL:10m;             # SSL TCP会话缓存设置共享内存区域名为
  12.                                                         # SSL,区域大小为10MB
  13.         ssl_session_timeout 10m;                        # SSL TCP会话缓存超时时间为10分钟
  14.         proxy_protocol    on; # 开启proxy_protocol获取真实ip
  15.         proxy_pass        127.0.0.1:1234; # 后端Trojan监听端口
  16.     }
  17. }

  18. http {

  19.     ##
  20.     # Basic Settings
  21.     ##


继续重载nginx检查是否报错

  1. systemctl restart nginx.service



注意事项:
1. 请配置SSL证书
2. proxy_pass 127.0.0.1:1234 后端Trojan监听端口与您网站前端节点监听端口一致
3. listen端口可以1-65535随意修改,此处为客户端连接端口

部署XrayR

XrayR一键部署

  1. bash <(curl -Ls https://raw.githubusercontent.com/XrayR-project/XrayR-release/master/install.sh)


配置文件路径:/etc/XrayR/config.yml

XrayR Trojan配置

关键配置:

ListenIP: 127.0.0.1

EnableProxyProtocol: true

EnableFallback: true

CertMode: none

注意1:请务必确保CertMode为none,交由Nginx处理tls

注意2:在回落时请确保回落站点是http1.1,nginx如果有一个站点是h2会导致全部站点都变成h2(巨坑)

完整样例

  1. -
  2. PanelType: "SSpanel" # Panel type: SSpanel, V2board, PMpanel
  3. ApiConfig:
  4. ApiHost: "https://xxx.com"
  5. ApiKey: "123"
  6. NodeID: 1
  7. NodeType: Trojan # Node type: V2ray, Shadowsocks, Trojan
  8. Timeout: 10 # Timeout for the api request
  9. EnableVless: false # Enable Vless for V2ray Type
  10. EnableXTLS: false # Enable XTLS for V2ray and Trojan
  11. SpeedLimit: 0 # Mbps, Local settings will replace remote settings, 0 means disable
  12. DeviceLimit: 0 # Local settings will replace remote settings, 0 means disable
  13. RuleListPath: # /etc/XrayR/rulelist Path to local rulelist file
  14. ControllerConfig:
  15. ListenIP: 127.0.0.1 # IP address you want to listen
  16. SendIP: 0.0.0.0 # IP address you want to send pacakage
  17. UpdatePeriodic: 60 # Time to update the nodeinfo, how many sec.
  18. EnableDNS: false # Use custom DNS config, Please ensure that you set the dns.json well
  19. DNSType: AsIs # AsIs, UseIP, UseIPv4, UseIPv6, DNS strategy
  20. EnableProxyProtocol: true # Only works for WebSocket and TCP
  21. EnableFallback: true # Only support for Trojan and Vless
  22. FallBackConfigs: # Support multiple fallbacks
  23. -
  24. SNI: # TLS SNI(Server Name Indication), Empty for any
  25. Path: # HTTP PATH, Empty for any
  26. Dest: fake.website.com:80 # Required, Destination of fallback, check https://xtls.github.io/config/fallback/ for details.
  27. ProxyProtocolVer: 0 # Send PROXY protocol version, 0 for dsable
  28. CertConfig:
  29. CertMode: none # Option about how to get certificate: none, file, http, dns. Choose "none" will forcedly disable the tls config.
  30. CertDomain: "node1.test.com" # Domain to cert
  31. CertFile: /etc/XrayR/cert/node1.test.com.cert # Provided if the CertMode is file
  32. KeyFile: /etc/XrayR/cert/node1.test.com.key
  33. Provider: alidns # DNS cert provider, Get the full support list here: https://go-acme.github.io/lego/dns/
  34. Email: test@me.com
  35. DNSEnv: # DNS ENV option used by DNS provider
  36. ALICLOUD_ACCESS_KEY: aaa
  37. ALICLOUD_SECRET_KEY: bbb


重启并检查 Nginx 和 XrayR

  1. systemctl restart nginx
  2. XrayR restart

  1. systemctl status nginx
  2. XrayR status