月度归档:2025年08月

docker部署3x-ui且配置ssl

如果你的服务器使用 Nginx 或其他 Web 服务器,安装对应的 Certbot 插件(例如 python3-certbot-apache)。
sudo apt install certbot python3-certbot-nginx

运行以下命令为你的域名生成证书
sudo certbot –nginx -d yourdomain.com

替换 yourdomain.com 为你的实际域名。
–standalone 模式适用于没有运行 Web 服务器的情况(确保 80 端口未被占用)。
证书默认存储在 /etc/letsencrypt/live/yourdomain.com/,包含 fullchain.pem(证书)和 privkey.pem(私钥)。

确保证书生成成功:
ls /etc/letsencrypt/live/yourdomain.com/

创建目录3x-ui,新建docker-compose.yml写入以下内容

services:
3x-ui:
image: ghcr.io/mhsanaei/3x-ui:latest
container_name: 3x-ui
hostname: 213879.xyz
volumes:
- ./db/:/etc/x-ui/
- /etc/letsencrypt/:/etc/letsencrypt/:rw
- /etc/letsencrypt/live/213879.xyz/fullchain.pem:/etc/letsencrypt/live/213879.xyz/fullchain.pem:ro
- /etc/letsencrypt/live/213879.xyz/privkey.pem:/etc/letsencrypt/live/213879.xyz/privkey.pem:ro
environment:
XRAY_VMESS_AEAD_FORCED: "true"
XRAY_USE_TLS: "ture"
XRAY_WORKER_THREADS: "4"
X_UI_ENABLE_FAIL2BAN: "true"
tty: true
ports:
- "25505:3300"
- "65321:2053"
- "35505:35505"
restart: unless-stopped
deploy:
resources:
limits:
cpus: '0.8'
memory: '512M'
reservations:
cpus: '0.20'
memory: '128M'
logging:
driver: "json-file"
options:
max-size: "1m"
max-file: "3"

在面板后填入证书路径
Let’s Encrypt 证书有效期为 90 天,需配置自动续期。
测试续期
sudo certbot renew --dry-run

设置自动续期
Certbot 默认会添加一个 cron 任务或 systemd 定时器来自动续期。你可以检查
sudo systemctl status certbot.timer
如果未启用,可手动添加 cron 任务:
echo "0 0,12 * * * root certbot renew --quiet" | sudo tee -a /etc/crontab

更新容器证书
证书续期后,需重启 3X-UI 容器以加载新证书:
docker compose restart