No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
kotoyuuko c828daf2f8 Allow HTTP port 80 through UFW for certbot ACME validation
certbot standalone mode requires port 80 to be accessible for ACME HTTP-01
validation. UFW was configured with default deny and only SSH was allowed,
blocking certbot from obtaining certificates. Add UFW allow rule for port 80
before certbot attempts certificate provisioning.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-29 15:13:36 +08:00
credentials Initialize Ansible proxy deployment project 2026-04-29 13:25:21 +08:00
group_vars Initialize Ansible proxy deployment project 2026-04-29 13:25:21 +08:00
inventory Support per-host Trojan domain configuration 2026-04-29 13:47:24 +08:00
openspec Allow HTTP port 80 through UFW for certbot ACME validation 2026-04-29 15:13:36 +08:00
roles Allow HTTP port 80 through UFW for certbot ACME validation 2026-04-29 15:13:36 +08:00
.gitignore Initialize Ansible proxy deployment project 2026-04-29 13:25:21 +08:00
ansible.cfg Initialize Ansible proxy deployment project 2026-04-29 13:25:21 +08:00
README.md Support per-host Trojan domain configuration 2026-04-29 13:47:24 +08:00
site.yml Initialize Ansible proxy deployment project 2026-04-29 13:25:21 +08:00
users.yml.example Initialize Ansible proxy deployment project 2026-04-29 13:25:21 +08:00

Ansible Proxy Deploy

支持多服务器一键部署 Trojan(多用户)和 Snell(单用户)代理服务的 Ansible 配置。

特性

  • 基础安全配置:SSH 加固、UFW 防火墙、fail2ban、自动安全更新
  • Snell 服务:单用户模式,支持自动 PSK 生成
  • Trojan 服务:多用户模式,用户通过 YAML 文件配置
  • TLS 自动管理:Let's Encrypt 证书自动申请和续期
  • systemd 托管:所有服务使用 systemd 单元管理

目录结构

.
├── ansible.cfg              # Ansible 配置
├── site.yml                 # 主 playbook
├── inventory/
│   └── hosts.yml.example    # 主机清单模板
├── group_vars/
│   └── all.yml              # 全局变量
├── roles/
│   ├── base/                # 基础安全配置
│   ├── snell/               # Snell 代理服务
│   └── trojan/              # Trojan 代理服务(多用户)
├── credentials/             # 自动生成的凭据(gitignored)
├── users.yml                # Trojan 用户配置(gitignored)
└── output/                  # 输出目录(gitignored)

快速开始

1. 配置主机清单

cp inventory/hosts.yml.example inventory/hosts.yml

编辑 inventory/hosts.yml,填入你的服务器信息:

all:
  children:
    servers:
      hosts:
        server1:
          ansible_host: 1.2.3.4
          ansible_user: ubuntu
          ssh_port: 22
    snell:
      children:
        servers:
    trojan:
      children:
        servers:

2. 配置 Trojan 用户

cp users.yml.example users.yml

编辑 users.yml:

trojan_users:
  - name: alice
    password: "your-secure-password-1"
  - name: bob
    password: "your-secure-password-2"

密码留空会自动生成 32 位随机密码并保存到 credentials/ 目录。

3. 配置域名和邮箱

在 inventory/hosts.yml 中为每台部署 Trojan 的服务器单独配置域名和邮箱:

all:
  children:
    servers:
      hosts:
        server1:
          ansible_host: 1.2.3.4
          ansible_user: ubuntu
          ssh_port: 22
          trojan_domain: "proxy1.example.com"
          certbot_email: "admin@example.com"
        server2:
          ansible_host: 5.6.7.8
          ansible_user: ubuntu
          ssh_port: 22
          trojan_domain: "proxy2.example.com"
          certbot_email: "admin@example.com"

每台 Trojan 服务器必须拥有独立的域名,且域名已解析到对应服务器的公网 IP。

4. 部署

# 部署全部服务
ansible-playbook site.yml

# 仅部署基础配置
ansible-playbook site.yml --tags base

# 仅部署 Snell
ansible-playbook site.yml --limit snell

# 仅部署 Trojan
ansible-playbook site.yml --limit trojan

配置变量

Snell 变量(roles/snell/defaults/main.yml)

变量 默认值 说明
snell_version v5.0.1 Snell 版本
snell_port 61080 监听端口
snell_psk 自动生成 预共享密钥
snell_ipv6 false 是否启用 IPv6

Trojan 变量(roles/trojan/defaults/main.yml)

变量 默认值 说明
trojan_version 0.10.6 trojan-go 版本
trojan_port 443 监听端口
trojan_fallback_port 8080 nginx fallback 端口
trojan_domain "" TLS 证书域名(必填)
certbot_email "" Let's Encrypt 邮箱(必填)

注意事项

  • 首次运行前确保域名已解析到目标服务器 IP
  • SSH 加固后会禁用密码登录和 root 登录,请确保已配置 SSH 密钥
  • inventory/hosts.yml、users.yml 和 credentials/ 已被 .gitignore 排除,请勿手动提交