@@ -6,6 +6,8 @@ Ansible role that installs and configures [Xray-core](https://github.com/XTLS/Xr
66- Xray with VLESS + XTLS-Reality and XHTTP inbounds
77- Optional VLESS Encryption (post-quantum, mlkem768x25519plus)
88- Raven-subscribe — subscription server for client config distribution
9+ - nginx TLS frontend on EU server (` nginx_frontend ` role)
10+ - nginx relay on RU server with TCP stream proxy for VLESS Reality (` relay ` role)
911- Systemd services with auto-restart and config validation before reload
1012- Ad/tracker blocking via geosite routing rules
1113- BBR congestion control and kernel tuning via ` srv_prepare ` role
@@ -24,12 +26,24 @@ Edit `roles/hosts.yml` and point `vm_my_srv` at your server.
2426
2527### 2. Secrets
2628
27- Create and encrypt the secrets file :
29+ Create and encrypt secrets files for each role you deploy :
2830
2931``` bash
32+ # Xray role (Reality keys, users)
3033cp roles/xray/defaults/secrets.yml.example roles/xray/defaults/secrets.yml
31- # Fill in the values (see Secrets section below)
3234ansible-vault encrypt roles/xray/defaults/secrets.yml --vault-password-file vault_password.txt
35+
36+ # Raven-subscribe role (admin token, server host, per-inbound overrides)
37+ cp roles/raven_subscribe/defaults/secrets.yml.example roles/raven_subscribe/defaults/secrets.yml
38+ ansible-vault encrypt roles/raven_subscribe/defaults/secrets.yml --vault-password-file vault_password.txt
39+
40+ # nginx_frontend role (certbot email) — EU server
41+ cp roles/nginx_frontend/defaults/secrets.yml.example roles/nginx_frontend/defaults/secrets.yml
42+ ansible-vault encrypt roles/nginx_frontend/defaults/secrets.yml --vault-password-file vault_password.txt
43+
44+ # relay role (upstream EU IP, certbot email) — RU server
45+ cp roles/relay/defaults/secrets.yml.example roles/relay/defaults/secrets.yml
46+ ansible-vault encrypt roles/relay/defaults/secrets.yml --vault-password-file vault_password.txt
3347```
3448
3549To edit later:
@@ -49,22 +63,31 @@ xray x25519
4963### 4. Deploy
5064
5165``` bash
66+ # EU server: Xray
5267ansible-playbook roles/role_xray.yml -i roles/hosts.yml --vault-password-file vault_password.txt
68+
69+ # EU server: nginx TLS frontend
70+ ansible-playbook roles/role_nginx_frontend.yml -i roles/nginx_frontend/inventory.ini --vault-password-file vault_password.txt
71+
72+ # EU server: Raven-subscribe
73+ ansible-playbook roles/role_raven_subscribe.yml -i roles/hosts.yml --vault-password-file vault_password.txt
74+
75+ # RU server: nginx relay
76+ ansible-playbook roles/role_relay.yml -i roles/relay/inventory.ini --vault-password-file vault_password.txt
5377```
5478
5579Deploy only a specific component using tags:
5680
5781``` bash
58- # Update subscription server config only
59- ansible-playbook roles/role_xray.yml -i roles/hosts.yml --vault-password-file vault_password.txt --tags raven_subscribe
60-
6182# Update inbound configs only
6283ansible-playbook roles/role_xray.yml -i roles/hosts.yml --vault-password-file vault_password.txt --tags xray_inbounds
6384```
6485
65- ## Secrets (` roles/xray/defaults/secrets.yml ` )
86+ ## Secrets
87+
88+ Each role has its own ` defaults/secrets.yml ` (ansible-vault encrypted).
6689
67- Ansible-vault encrypted. Required fields :
90+ ** ` roles/xray/defaults/secrets.yml ` ** — Reality keys and VLESS users :
6891
6992``` yaml
7093# Reality keys — generate with: xray x25519
@@ -80,11 +103,29 @@ xray_users:
80103 - id : " xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" # UUID — generate: uuidgen
81104 flow : " xtls-rprx-vision"
82105 email : " user@example.com"
106+ ` ` `
107+
108+ **` roles/raven_subscribe/defaults/secrets.yml`** — Raven-subscribe settings:
109+
110+ ` ` ` yaml
111+ raven_subscribe_admin_token: "" # openssl rand -hex 32
112+ raven_subscribe_server_host: "media.zirgate.com"
113+ raven_subscribe_base_url: "https://media.zirgate.com"
114+
115+ # Per-inbound host/port overrides (optional)
116+ # Useful when clients should connect through a relay instead of the EU server directly
117+ raven_subscribe_inbound_hosts:
118+ vless-reality-in: "media.zirgate.com"
119+ vless-xhttp-in: "media.zirgate.com"
120+ raven_subscribe_inbound_ports:
121+ vless-reality-in: 8445 # nginx stream relay port on EU server
122+ ` ` `
123+
124+ **`roles/relay/defaults/secrets.yml`** — RU server relay:
83125
84- # Raven-subscribe
85- raven_subscribe_admin_token : " " # openssl rand -hex 32
86- raven_subscribe_server_host : " your-server.com"
87- raven_subscribe_base_url : " http://your-server.com:8080"
126+ ` ` ` yaml
127+ relay_upstream_host: "1.2.3.4" # EU server IP
128+ relay_certbot_email: "admin@example.com"
88129` ` `
89130
90131# # Configuration
@@ -98,29 +139,62 @@ Key variables in `roles/xray/defaults/main.yml`:
98139| `xray_reality_server_names` | `["askubuntu.com"]` | SNI names for Reality |
99140| `xray_xhttp.port` | `2053` | XHTTP inbound port |
100141| `xray_dns_servers` | `tcp+local://8.8.8.8, ...` | DNS servers (no DoH — see note below) |
142+ | `xray_dns_query_strategy` | `UseIPv4` | DNS query strategy — use `UseIPv4` if the server has no IPv6 |
101143| `xray_vless_decryption` | `"none"` | VLESS Encryption (optional, see below) |
144+
145+ Key variables in `roles/raven_subscribe/defaults/main.yml` :
146+
147+ | Variable | Default | Description |
148+ |----------|---------|-------------|
102149| `raven_subscribe_listen_addr` | `:8080` | Raven-subscribe listen address |
103150| `raven_subscribe_sync_interval_seconds` | `60` | User sync interval |
151+ | `raven_subscribe_inbound_hosts` | `{}` | Per-inbound host overrides (set in secrets.yml) |
152+ | `raven_subscribe_inbound_ports` | `{}` | Per-inbound port overrides (set in secrets.yml) |
104153
105154> **DNS note:** Do not use `https://` (DoH) in `xray_dns_servers` — DoH queries route through the proxy and fail. Use `tcp+local://` instead.
106155
107156# # Architecture
108157
109158```
110- roles/role_xray.yml
111- └── srv_prepare — system packages, BBR, sysctl tuning
112- └── xray — Xray + Raven-subscribe
113- ├── validate.yml (always) — pre-flight assertions
114- ├── install.yml (xray_install) — download Xray binary
115- ├── base.yml (xray_base) — log + stats config
116- ├── api.yml (xray_api) — gRPC API on 127.0.0.1:10085
117- ├── inbounds.yml (xray_inbounds) — VLESS+Reality, XHTTP
118- ├── dns.yml (xray_dns) — DNS config
119- ├── outbounds.yml (xray_outbounds) — direct + block outbounds
120- ├── routing.yml (xray_routing) — routing rules + ad blocking
121- ├── service.yml (xray_service) — systemd unit
122- ├── grpcurl.yml (grpcurl) — installs grpcurl tool
123- └── raven_subscribe.yml (raven_subscribe) — subscription server
159+ EU server
160+ role_xray.yml
161+ └── srv_prepare — system packages, BBR, sysctl tuning
162+ └── xray — Xray binary + config
163+ ├── validate.yml (always) — pre-flight assertions
164+ ├── install.yml (xray_install) — download Xray binary
165+ ├── base.yml (xray_base) — log + stats config
166+ ├── api.yml (xray_api) — gRPC API on 127.0.0.1:10085
167+ ├── inbounds.yml (xray_inbounds) — VLESS+Reality, XHTTP
168+ ├── dns.yml (xray_dns) — DNS config
169+ ├── outbounds.yml (xray_outbounds) — direct + block outbounds
170+ ├── routing.yml (xray_routing) — routing rules + ad blocking
171+ ├── service.yml (xray_service) — systemd unit
172+ └── grpcurl.yml (grpcurl) — installs grpcurl tool
173+
174+ role_nginx_frontend.yml
175+ └── nginx_frontend — nginx TLS proxy on media.zirgate.com
176+ ├── listens on port 8443 (not 443, reserved by Xray Reality)
177+ ├── proxies /sub/* → Raven-subscribe :8080
178+ └── stream TCP relay: port 8445 → 127.0.0.1:443 (Xray Reality)
179+
180+ role_raven_subscribe.yml
181+ └── raven_subscribe — subscription server
182+ ├── listens on 127.0.0.1:8080
183+ ├── syncs users to Xray via gRPC API
184+ └── serves client configs with per-inbound host/port overrides
185+
186+ RU server
187+ role_relay.yml
188+ └── relay — nginx reverse proxy on zirgate.com
189+ ├── my.zirgate.com → https://media.zirgate.com:8443 (Raven)
190+ └── stream TCP relay: port 8444 → media.zirgate.com:8445 (Reality)
191+ ```
192+
193+ Client connection flow:
194+ ```
195+ VLESS Reality: client → zirgate.com:8444 (RU TCP relay) → media.zirgate.com:8445 (EU nginx stream) → 127.0.0.1:443 (Xray)
196+ VLESS XHTTP: client → media.zirgate.com:443/path → nginx_frontend:8443 → Xray :2053
197+ Subscription: client → my.zirgate.com (RU relay) → media.zirgate.com:8443 → Raven-subscribe :8080
124198```
125199
126200Xray config is split across `/etc/xray/config.d/` — files are loaded in numeric order:
0 commit comments