静看光阴荏苒
不管不顾不问不说也不念

XrayR后端的TLS交给Nginx处理的配置

在之前我记录了一下xrayr后端节点的常用配置方法,在这种方法下,tls是直接由xrayr处理的,这样一来会有一些问题。

首先为了避免机器被墙,现在无一例外肯定是使用vmess+websocket+tls或者vless+xtls(xrayr是支持的)

但无论你使用上面提到的这两种方法的哪一种,都是非常依赖443端口的,如果让xrayr直接监听443的话,机器就不能再做其他事情了。比如用nginx或者caddy建站就不能https了。

用其他端口配置吧,又显得有点不伦不类。所以最好的办法是让nginx来处理tls,这样443端口就可以腾出来给nginx用了。

vless+xtls其实是目前更推荐的配置方法,但是目前v2board面板的订阅还不支持,所以下面我就用vmess+websocket+tls来演示一下配置。

首先在节点上安装需要用到的包:

apt -y update
apt -y install nginx python-certbot-nginx supervisor

启动服务并设置开机自启:

systemctl enable --now nginx supervisor

接着在v2board面板内添加一个websocket节点:

注意这里的连接端口和服务端口,连接端口配置为443,服务端口配置为4443。

连接端口就相当于是用户通过订阅连接配置在客户端上的端口,而服务端口是xrayr后端实际监听的端口。

另外别忘了配置path:

现在新建一个nginx站点配置文件:

nano /etc/nginx/conf.d/xrayr.conf

写入如下配置:

server {
    listen       80;
    server_name  rucn2.ohshit.club;

    location /sometimesnaive {
        proxy_pass                       http://127.0.0.1:4443;
        proxy_redirect                   off;
        proxy_http_version               1.1;
        proxy_set_header Upgrade         $http_upgrade;
        proxy_set_header Connection      "upgrade";
        proxy_set_header Host            $http_host;
        proxy_set_header X-Real-IP       $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

剩下给nginx配置ssl证书的这些步骤全部交给certbot自动帮我们处理即可:

certbot --nginx

现在安装xrayr:

mkdir /opt/xrayr && cd /opt/xrayr
wget https://github.com/XrayR-project/XrayR/releases/download/v0.5.0/XrayR-linux-64.zip

编辑xrayr配置文件:

nano config.yml

改为如下配置,重要部分写了注释:

Log:
  Level: debug
  AccessPath: ./access.log
  ErrorPath: ./error.log
DnsConfigPath: ./dns.json
Nodes:
  -
    PanelType: "V2board"
    ApiConfig:
      ApiHost: "https://v2board.ohshit.club/"
      ApiKey: "imlalaimlalaimlala"
      NodeID: 4 // 对应v2board面板内的节点id
      NodeType: V2ray
      Timeout: 30
      EnableVless: false
      EnableXTLS: false
    ControllerConfig:
      ListenIP: 127.0.0.1 // 仅监听在本地
      UpdatePeriodic: 60
      EnableDNS: false
      CertConfig:
        CertMode: none // 关闭证书申请
        CertDomain: "rucn2.ohshit.club" 
        Provider: cloudflare 
        Email: example@lala.im
        DNSEnv: 
          CF_DNS_API_TOKEN: cwPZEBAvIXUcxCdy4v2ib5j8uK-KwnRMDuNPxE-n

新建supervisor配置文件用于守护xrayr:

nano /etc/supervisor/conf.d/xrayr.conf

写入如下配置:

[program:xrayr]
directory=/opt/xrayr
command=/opt/xrayr/XrayR -config config.yml
autostart=true
autorestart=true

启动xrayr:

supervisorctl update

至此配置就全部完成了。对接有任何问题,查看相应的日志文件有助于排错:

/opt/xrayr/access.log
/opt/xrayr/error.log
赞(5)
未经允许不得转载:荒岛 » XrayR后端的TLS交给Nginx处理的配置
分享到: 更多 (0)

评论 9

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #1

    如何更改nginx的访问界面

    23333年前 (2021-06-12) Google Chrome 91.0.4472.101 Google Chrome 91.0.4472.101 Windows 10 x64 Edition Windows 10 x64 Edition回复
  2. #2

    80、443被服务商屏蔽了?怎么换2096\2087的端口?

    yj3年前 (2021-09-12) Google Chrome 93.0.4577.63 Google Chrome 93.0.4577.63 Windows 10 x64 Edition Windows 10 x64 Edition回复
  3. #3

    一直没搞明白tls和xtls的关系。这俩配置互斥吗?
    “`
    EnableVless: false
    EnableXTLS: false //开启xtls是不是这里设置为true就行了?这里设置为true后,后面的 `CertConfig:` 能开启域名认证申请证书吗?还是开了xtls后面就必须开启认证申请证书才行?
    “`

    哼哼哈嘿2年前 (2021-12-01) Microsoft Edge 96.0.1054.41 Microsoft Edge 96.0.1054.41 Windows 10 x64 Edition Windows 10 x64 Edition回复
    • xtls兼容tls,开了xtls务必开启vless。

      LALA2年前 (2021-12-11) Google Chrome 86.0.4240.198 Google Chrome 86.0.4240.198 Windows 10 x64 Edition Windows 10 x64 Edition回复
      • 谢谢岛主解答。
        开了xtls后必须开tls吗?还是开了xtls后tls选项可开可不开?

        哼哼哈嘿2年前 (2021-12-22) Microsoft Edge 96.0.1054.57 Microsoft Edge 96.0.1054.57 Windows 10 x64 Edition Windows 10 x64 Edition回复
        • 开了xtls后就不用开tls了,因为xtls兼容tls。即便你服务端设置的是xtls,用户在客户端配置为tls也能连接。

          LALA2年前 (2021-12-22) Google Chrome 86.0.4240.198 Google Chrome 86.0.4240.198 Windows 10 x64 Edition Windows 10 x64 Edition回复
  4. #4

    :mrgreen: Unable to locate package python-certbot-nginx
    改成python3-certbot-nginx

    thanks2年前 (2022-09-21) Google Chrome 105.0.0.0 Google Chrome 105.0.0.0 Windows 10 x64 Edition Windows 10 x64 Edition回复
  5. #5

    :!: 能出两包烟钱,让博主在写详细点的加上套用cf的cnd教程吗?用着用着出现问题了搜索解决不了,,,,

    zero7个月前 (09-27) Google Chrome 114.0.0.0 Google Chrome 114.0.0.0 Windows 10 x64 Edition Windows 10 x64 Edition回复

分享创造快乐

广告合作资源投稿