Skip to content

Commit d2608f2

Browse files
authored
Merge pull request #4 from AlchemyLink/feature/singbox-role-refactor
feat: extract raven_subscribe, nginx_frontend, relay into separate Ansible roles
2 parents 9acc0f9 + f9e0710 commit d2608f2

50 files changed

Lines changed: 953 additions & 46 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Secrets — never commit real credentials
22
vault_password.txt
33
**/secrets.yml
4+
**/*_secrets.yml
45
**/vault_password.txt
56
**/*.secret
67
**/*.vault
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
# nginx_frontend role — TLS frontend for EU server (media.zirgate.com)
3+
#
4+
# Responsibilities:
5+
# - Install nginx + certbot
6+
# - Obtain Let's Encrypt certificate for nginx_frontend_domain
7+
# - Proxy Xray XHTTP (nginx_frontend_xhttp_path) → 127.0.0.1:nginx_frontend_xhttp_port
8+
9+
# ── Domain ────────────────────────────────────────────────────────────────────
10+
nginx_frontend_domain: "media.zirgate.com"
11+
12+
# ── Certbot ───────────────────────────────────────────────────────────────────
13+
nginx_frontend_certbot_email: "" # Set in secrets.yml
14+
15+
# ── nginx listen port ─────────────────────────────────────────────────────────
16+
# IMPORTANT: Xray VLESS Reality already binds to 443 (TCP).
17+
# nginx_frontend must listen on a different port (e.g., 8443, 9443).
18+
# The relay role will proxy to this port over HTTPS with SNI.
19+
nginx_frontend_listen_port: 8443 # Must NOT conflict with xray_vless_port (443)
20+
21+
# ── Raven-subscribe upstream ──────────────────────────────────────────────────
22+
nginx_frontend_raven_port: 8080 # Must match raven_subscribe_listen_addr port
23+
24+
# ── Xray XHTTP upstream ───────────────────────────────────────────────────────
25+
nginx_frontend_xhttp_port: 2053 # Must match xray_xhttp.port
26+
nginx_frontend_xhttp_path: "/api/v3/data-sync" # Must match xray_xhttp.xhttpSettings.path
27+
28+
# ── TCP stream relay for Xray VLESS Reality ───────────────────────────────────
29+
# Stream proxy: nginx_frontend_reality_port → 127.0.0.1:443 (Xray)
30+
# Allows clients to reach Reality via media.zirgate.com instead of direct EU IP.
31+
nginx_frontend_reality_stream_enabled: true
32+
nginx_frontend_reality_port: 8445 # External TCP port for Reality stream
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
# Copy to secrets.yml and encrypt with ansible-vault:
3+
# ansible-vault encrypt roles/nginx_frontend/defaults/secrets.yml
4+
5+
nginx_frontend_certbot_email: "admin@admin.com"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- name: Reload nginx
3+
ansible.builtin.service:
4+
name: nginx
5+
state: reloaded
6+
7+
- name: Restart nginx
8+
ansible.builtin.service:
9+
name: nginx
10+
state: restarted

roles/nginx_frontend/inventory.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[eu]
2+
vpn ansible_host=EU_VPS_IP ansible_user=deploy
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
- name: Nginx frontend | Check if certificate exists
3+
ansible.builtin.stat:
4+
path: "/etc/letsencrypt/live/{{ nginx_frontend_domain }}/fullchain.pem"
5+
register: nginx_frontend_cert
6+
7+
- name: Nginx frontend | Obtain Let's Encrypt certificate
8+
ansible.builtin.command:
9+
cmd: >
10+
certbot certonly --webroot
11+
--webroot-path /var/www/letsencrypt
12+
--non-interactive
13+
--agree-tos
14+
--email {{ nginx_frontend_certbot_email }}
15+
-d {{ nginx_frontend_domain }}
16+
when: not nginx_frontend_cert.stat.exists
17+
notify: Reload nginx
18+
19+
- name: Nginx frontend | Ensure certbot renewal timer is enabled
20+
ansible.builtin.service:
21+
name: certbot.timer
22+
enabled: true
23+
state: started
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
- name: Nginx frontend | Install nginx and certbot
3+
ansible.builtin.apt:
4+
name:
5+
- nginx
6+
- certbot
7+
- python3-certbot-nginx
8+
state: present
9+
update_cache: true
10+
11+
- name: Nginx frontend | Ensure nginx is enabled and started
12+
ansible.builtin.service:
13+
name: nginx
14+
enabled: true
15+
state: started
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
- name: Nginx frontend | Validate
3+
ansible.builtin.import_tasks: validate.yml
4+
tags: always
5+
6+
- name: Nginx frontend | Install packages
7+
ansible.builtin.import_tasks: install.yml
8+
tags: nginx_frontend_install
9+
10+
- name: Nginx frontend | Configure HTTP (pre-certbot)
11+
ansible.builtin.import_tasks: nginx.yml
12+
tags: nginx_frontend_nginx
13+
14+
- name: Nginx frontend | Obtain TLS certificate
15+
ansible.builtin.import_tasks: certbot.yml
16+
tags: nginx_frontend_certbot
17+
18+
- name: Nginx frontend | Deploy HTTPS config
19+
ansible.builtin.import_tasks: nginx_ssl.yml
20+
tags: nginx_frontend_ssl
21+
22+
- name: Nginx frontend | Configure TCP stream relay
23+
ansible.builtin.import_tasks: stream.yml
24+
tags: nginx_frontend_stream
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
- name: Nginx frontend | Create letsencrypt webroot
3+
ansible.builtin.file:
4+
path: /var/www/letsencrypt
5+
state: directory
6+
owner: root
7+
group: root
8+
mode: "0755"
9+
10+
- name: Nginx frontend | Deploy HTTP config (pre-certbot)
11+
ansible.builtin.template:
12+
src: nginx/http.conf.j2
13+
dest: "/etc/nginx/conf.d/{{ nginx_frontend_domain }}.conf"
14+
owner: root
15+
group: root
16+
mode: "0644"
17+
notify: Reload nginx
18+
19+
- name: Nginx frontend | Reload nginx before certbot
20+
ansible.builtin.meta: flush_handlers
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
- name: Nginx frontend | Deploy HTTPS config
3+
ansible.builtin.template:
4+
src: nginx/https.conf.j2
5+
dest: "/etc/nginx/conf.d/{{ nginx_frontend_domain }}.conf"
6+
owner: root
7+
group: root
8+
mode: "0644"
9+
notify: Reload nginx

0 commit comments

Comments
 (0)