apisix/ssl_manager/CONFIG.md

122 lines
3.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 配置说明
## 配置方式
配置已直接定义在 Python 文件中,**不需要** `config.json` 文件。
### 方式一:直接修改 Python 文件(推荐)
编辑 Python 文件中的 `DEFAULT_CONFIG` 字典:
#### ssl_manager.py
```python
DEFAULT_CONFIG = {
'apisix_admin_url': 'http://localhost:9180',
'apisix_admin_key': '8206e6e42b6b53243c52a767cc633137',
'certbot_path': '/usr/bin/certbot',
'cert_dir': '/etc/letsencrypt/live',
'letsencrypt_email': 'admin@jingrowtools.cn', # 修改为你的邮箱
'letsencrypt_staging': True, # 生产环境改为 False
'webroot_path': '/var/www/certbot'
}
```
#### test_ssl_auto.py
```python
DEFAULT_TEST_CONFIG = {
'apisix_admin_url': 'http://localhost:9180',
'apisix_admin_key': '8206e6e42b6b53243c52a767cc633137',
'webroot_path': '/var/www/certbot',
'letsencrypt_staging': True
}
```
### 方式二:使用环境变量(推荐用于生产环境)
通过环境变量覆盖默认配置:
```bash
export APISIX_ADMIN_URL="http://localhost:9180"
export APISIX_ADMIN_KEY="your-admin-key"
export LETSENCRYPT_EMAIL="your-email@example.com"
export LETSENCRYPT_STAGING="false"
export WEBROOT_PATH="/var/www/certbot"
```
### 方式三:使用配置文件(可选,向后兼容)
如果仍想使用 `config.json`,可以创建它,配置会覆盖默认值:
```json
{
"apisix_admin_url": "http://localhost:9180",
"apisix_admin_key": "your-admin-key",
"certbot_path": "/usr/bin/certbot",
"cert_dir": "/etc/letsencrypt/live",
"letsencrypt_email": "your-email@example.com",
"letsencrypt_staging": false,
"webroot_path": "/var/www/certbot"
}
```
然后使用 `--config` 参数:
```bash
python3 ssl_manager.py request --domain example.com --config config.json
```
## 配置优先级
1. **环境变量**(最高优先级)
2. **配置文件**(如果使用 `--config` 参数)
3. **Python 文件中的 DEFAULT_CONFIG**(默认值)
## 配置项说明
| 配置项 | 说明 | 默认值 |
|--------|------|--------|
| `apisix_admin_url` | APISIX Admin API 地址 | `http://localhost:9180` |
| `apisix_admin_key` | APISIX Admin API 密钥 | `8206e6e42b6b53243c52a767cc633137` |
| `certbot_path` | Certbot 可执行文件路径 | `/usr/bin/certbot` |
| `cert_dir` | 证书存储目录 | `/etc/letsencrypt/live` |
| `letsencrypt_email` | Let's Encrypt 邮箱 | `admin@jingrowtools.cn` |
| `letsencrypt_staging` | 是否使用 staging 模式 | `True`(测试环境) |
| `webroot_path` | Webroot 验证文件路径 | `/var/www/certbot` |
## 快速配置
### 修改邮箱和切换到生产环境
编辑 `ssl_manager.py`
```python
DEFAULT_CONFIG = {
# ... 其他配置 ...
'letsencrypt_email': 'your-email@example.com', # 修改这里
'letsencrypt_staging': False, # 改为 False 使用生产环境
# ... 其他配置 ...
}
```
### 修改 APISIX Admin Key
编辑 `ssl_manager.py`
```python
DEFAULT_CONFIG = {
'apisix_admin_key': 'your-new-admin-key', # 修改这里
# ... 其他配置 ...
}
```
## 注意事项
1. **Staging 模式**:默认使用 staging 模式(测试环境),不会消耗生产环境配额
2. **生产环境**:切换到生产环境前,确保:
- 域名 DNS 已正确解析
- 80 端口可访问
- 验证路径可访问
3. **安全性**:不要将包含敏感信息的配置文件提交到版本控制系统