Skip to content

feat: SNI routing v2, PROXY protocol, monitoring improvements#7

Merged
findias merged 32 commits intodevelopfrom
feature/sni-routing-v2
Mar 28, 2026
Merged

feat: SNI routing v2, PROXY protocol, monitoring improvements#7
findias merged 32 commits intodevelopfrom
feature/sni-routing-v2

Conversation

@findias
Copy link
Copy Markdown
Contributor

@findias findias commented Mar 28, 2026

Summary

  • nginx stream SNI routing with proxy_protocol on — real client IPs passed to Xray via PROXY protocol v2 (xver: 2)
  • Per-inbound metrics: xray_inbound_uplink/downlink_bytes_total
  • Raven-subscribe health monitoring in Grafana (server-status dashboard)
  • Grafana alerting rules: xray-down, raven-subscribe-down, eu/ru-server-down, disk-high
  • xray-stats-exporter: new flags --log-path, --geo-city-db, --geo-asn-db
  • Dashboard cleanup: removed geo panels (data unavailable via PROXY protocol — Xray logs 127.0.0.1 after nginx fronting)
  • Fixes: xray-stats-exporter service user/group vars, binary copy skipped when not provided
  • docs: updated README with correct SNI routing architecture, ports, monitoring section

Deploy order (CRITICAL)

When deploying nginx_frontend and Xray inbounds together — always deploy Xray first (--tags xray_inbounds), then nginx. nginx starts sending PROXY protocol headers immediately; Xray must be ready to accept them (xver: 2).

Test plan

  • Xray connects after deploying both components
  • xray_up 1 in exporter metrics
  • Per-inbound metrics appear in Grafana
  • Raven-subscribe health panel shows UP

findias and others added 30 commits March 22, 2026 12:40
…bfs rendering

- Remove legacy `singbox_dns_servers` with `address:` prefix format (deprecated in 1.12)
- Add `singbox_dns_strategy` and `singbox_dns_final` variables for new format
- Update config.json.j2 to use variables instead of hardcoded DNS strategy
- Wrap `obfs` block in conditional: only render when obfs_enabled and obfs_password set
- Add tasks/*.yml and defaults/secrets.yml.example (new sing-box role files)
…dling

- Introduce `singbox_dns_strategy` and `singbox_dns_final` for improved DNS format compliance
- Update `config.json.j2` to utilize new variables instead of deprecated formats
- Conditional rendering of `obfs` block based on `obfs_enabled` and `obfs_password` settings
- Add new role files in tasks/*.yml and defaults/secrets.yml.example
- New role: raven_subscribe — standalone subscription server deployment,
  decoupled from xray/sing-box playbooks. Supports per-inbound host/port
  overrides (inbound_hosts, inbound_ports) for unified media.zirgate.com routing.
- New role: nginx_frontend — TLS proxy on EU server (media.zirgate.com),
  listens on 8443 (not 443, reserved by Xray Reality). Adds nginx stream
  TCP relay on port 8445 → 127.0.0.1:443 for VLESS Reality passthrough.
- New role: relay — nginx reverse proxy on RU VPS (zirgate.com/my.zirgate.com),
  TCP stream relay on 8444 → EU:8445 for VLESS Reality via RU server.
- xray role: remove raven_subscribe vars/tasks (moved to raven_subscribe role),
  fix DNS query strategy UseIP → UseIPv4 to avoid IPv6 unreachable errors.
- sing-box: update hysteria2 default port 8443 → 8444 (8443 now used by nginx_frontend).
- raven-subscribe config.j2: add balancer_strategy/probe_url/probe_interval fields.
- .gitignore: add **/*_secrets.yml pattern for raven_subscribe secrets files.
feat: extract raven_subscribe, nginx_frontend, relay into separate Ansible roles
…ides

- Add nginx_frontend and relay roles to What you get list
- Update Quick Start: separate secrets files per role, separate deploy commands
- Update Secrets section: document raven_subscribe/defaults/secrets.yml with inbound_hosts/inbound_ports example
- Update Configuration: add xray_dns_query_strategy, raven_subscribe_inbound_hosts/ports
- Update Architecture: show full EU+RU server topology and client connection flow
- roles/xray/README.md: remove xray_vless_default_flow (removed from templates)
docs: update README for multi-role architecture and per-inbound overr…
- Rewrite README.md with full architecture diagrams, role reference,
  secrets docs, DNS setup, VLESS Encryption and Hysteria2 sections
- Add README.ru.md (Russian translation, full parity with EN)
- Add roles/hosts.yml.example (safe template, no real IPs/usernames)
- Replace all personal domains (zirgate.com) with example.com in
  defaults, templates, inventory files, and playbook comments
- Remove leftover draft files: roles/xray/exampl/ directory
- Remove unused roles/xray/tasks/raven_subscribe.yml (moved to separate role)
- Fix role_nginx_frontend.yml and role_relay.yml: use inventory group
  names (eu/relay) instead of personal host names (vm_my_srv/vm_my_ru)
Both VPN protocols (VLESS+Reality TCP and VLESS+XHTTP+Reality) now share
port 443 via nginx stream ssl_preread SNI routing on both EU and RU servers.

EU server:
- nginx stream :443 routes by SNI: www.adobe.com → Xray XHTTP (:2053),
  media.zirgate.com → nginx HTTPS (:8443), default → Xray Reality (:4443)
- Xray inbounds bind 127.0.0.1 (no longer exposed directly)
- XHTTP Reality dest changed to www.adobe.com with xPaddingBytes

RU relay:
- Single stream :443 routes by SNI: zirgate.com/my.zirgate.com → local
  nginx HTTPS (:8443), everything else → EU:443
- Removed separate per-protocol stream ports (8444, 2053)

nginx_frontend HTTPS: removed XHTTP proxy location (now handled by stream)
Raven-subscribe: updated inbound_ports comments for port 443
…ra domains

- xray XHTTP scMaxPacketSize: 50000 → 1048576 (1MB) — reduces HTTP round-trips
- relay stream: add relay_extra_eu_https_domains for SNI routing to EU:8443
  (used when a domain's DNS is moved to RU but cert is on EU nginx)
…sites-enabled

- relay stream: remove relay_extra_eu_https_domains (no longer needed)
- nginx_frontend: deploy HTTPS config to sites-enabled/ instead of conf.d/
  (nginx.conf on EU only includes sites-enabled/)
- New role roles/wireguard: installs wireguard-tools, deploys wg0 on
  EU (10.10.0.1) and RU (10.10.0.2), PersistentKeepalive=25s
- role_wireguard.yml playbook applies to both vm_my_srv and vm_my_ru
- monitoring: remove ssh_tunnel_ru task/handler/vars; node_exporter on
  RU now binds to 10.10.0.2:9100 (WireGuard iface); VictoriaMetrics
  scrapes RU via 10.10.0.2:9100 instead of SSH tunnel 127.0.0.1:19100
- monitoring/node_exporter: add ufw allow from 10.10.0.0/24 for RU
- role_monitoring.yml: apply role to both EU and RU hosts; EU-only
  components (VictoriaMetrics, Grafana, exporters) guarded by when
Xray requires non-empty email for StatsService per-user counters.
If user.email is missing or blank, use user.id instead.
Applies to 200-in-vless-reality, 210-in-xhttp, 230/240-in-*-users.
GitHub /releases/latest returns enterprise release (no single-node
tarball). Switch to /releases list and find first release that has
victoria-metrics-linux-{arch}-vX.Y.Z.tar.gz (non-enterprise, non-cluster).
Also fix task order: detect arch before fetching releases list.
server-status: add unique_users (stat), total_connections (stat),
routing requests rate (freedom vs blocked), Xray heap memory timeseries.

xray-users-traffic: replace cumulative counter tables with bar gauges
using increase($__range) — shows traffic per user for selected period.
…ibe monitoring, Grafana alerts

- xray-stats-exporter: add xray_inbound_uplink/downlink_bytes_total metrics
  by querying inbound>>> pattern alongside user>>> in StatsService
- scrape.yml: add raven-subscribe job scraping /health (up=0 on failure)
- dashboards: add inbound traffic panels and sort_desc on user top charts
- server-status: add Raven-subscribe UP/DOWN status and latency panels
- grafana-alerting.yml: provision 5 alert rules (xray down, raven-subscribe
  down, EU/RU server down, EU disk >85%)
Geo metrics (country/city) not available — Xray access.log shows
127.0.0.1 after nginx proxy_protocol was added. Removed geo row
and shifted inbound panels up.
…t ports

- Fix architecture diagrams: SNI routing on :443, ports 4443/2053/8443
- Add nginx_frontend PROXY protocol notes and deploy order warning
- Add monitoring role description (xray-stats-exporter, VictoriaMetrics, Grafana)
- Add Monitoring section with Grafana dashboard and alerting description
- Update nginx_frontend and relay config variable tables
- Add xray-stats-exporter to Related Projects
- Sync README.ru.md with EN changes
@findias findias merged commit b6a0e9c into develop Mar 28, 2026
1 check passed
findias added a commit that referenced this pull request Apr 4, 2026
feat: SNI routing v2, PROXY protocol, monitoring improvements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant