Qwen3.5-9B-GGUF部署教程:Nginx反向代理配置、HTTPS支持与内网域名访问
Qwen3.5-9B-GGUF部署教程:Nginx反向代理配置、HTTPS支持与内网域名访问
1. 项目概述
Qwen3.5-9B-GGUF是阿里云开源的Qwen3.5-9B模型经过GGUF格式量化后的版本,采用Gated Delta Networks架构和混合注意力机制(75%线性+25%标准),原生支持256K tokens的超长上下文(约18万字)。本教程将指导您完成从基础部署到生产环境配置的全过程。
核心参数:
- 模型大小:90亿参数(9B)
- 量化版本:IQ4_NL(5.3GB)
- 协议:Apache 2.0(允许商用、微调和分发)
- WebUI端口:7860
2. 基础环境准备
2.1 模型与依赖安装
确保已完成以下基础部署:
- 模型文件已放置在指定路径:
/root/ai-models/unsloth/Qwen3___5-9B-GGUF/Qwen3.5-9B-IQ4_NL.gguf - 创建并激活conda环境:
source /opt/miniconda3/bin/activate torch28 - 安装核心依赖:
pip install llama-cpp-python gradio transformers
2.2 Supervisor服务配置
创建配置文件/etc/supervisor/conf.d/qwen3-9b-gguf.conf:
[program:qwen3-9b-gguf] command=/root/Qwen3.5-9B-GGUFit/start.sh directory=/root/Qwen3.5-9B-GGUFit user=root autostart=true autorestart=true stderr_logfile=/root/Qwen3.5-9B-GGUFit/service.log stdout_logfile=/root/Qwen3.5-9B-GGUFit/service.log重载Supervisor配置:
supervisorctl reread supervisorctl update3. Nginx反向代理配置
3.1 基础反向代理设置
编辑Nginx配置文件(如/etc/nginx/conf.d/qwen.conf):
server { listen 80; server_name your-domain.com; location / { proxy_pass http://localhost:7860; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 处理Gradio的WebSocket连接 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } }验证并重载Nginx:
nginx -t && nginx -s reload3.2 性能优化配置
在Nginx配置中添加以下参数:
# 提高超时设置 proxy_connect_timeout 600; proxy_send_timeout 600; proxy_read_timeout 600; send_timeout 600; # 启用gzip压缩 gzip on; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;4. HTTPS安全配置
4.1 获取SSL证书
使用Certbot获取Let's Encrypt证书:
sudo apt install certbot python3-certbot-nginx sudo certbot --nginx -d your-domain.com4.2 Nginx SSL配置
自动生成的配置会包含类似内容:
server { listen 443 ssl; server_name your-domain.com; ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem; # 安全强化配置 ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256...'; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; # 原有代理配置 location / { proxy_pass http://localhost:7860; # ...其他代理设置 } }5. 内网域名访问方案
5.1 本地DNS解析配置
在内网DNS服务器或本地hosts文件中添加记录:
192.168.1.100 qwen.internal.example.com5.2 内网专用Nginx配置
创建专用配置文件/etc/nginx/conf.d/qwen-internal.conf:
server { listen 80; server_name qwen.internal.example.com; # 限制内网访问 allow 192.168.1.0/24; deny all; location / { proxy_pass http://localhost:7860; # ...其他代理设置 } }6. 服务管理与监控
6.1 常用管理命令
# 查看服务状态 supervisorctl status qwen3-9b-gguf # 查看实时日志 tail -f /root/Qwen3.5-9B-GGUFit/service.log # 资源监控 htop -u root # 查看资源占用 nvidia-smi # GPU监控(如适用)6.2 开机自启动验证
确保Supervisor服务已设置为开机启动:
systemctl enable supervisor ls -l /etc/rc3.d/ | grep supervisor7. 常见问题排查
7.1 502 Bad Gateway错误
检查步骤:
- 确认后端服务运行状态:
supervisorctl status qwen3-9b-gguf - 检查端口监听:
netstat -tulnp | grep 7860 - 验证Nginx错误日志:
tail -50 /var/log/nginx/error.log
7.2 SSL证书续期问题
设置自动续期:
# 测试续期 certbot renew --dry-run # 添加定时任务(每月1号凌晨3点检查续期) (crontab -l 2>/dev/null; echo "0 3 1 * * /usr/bin/certbot renew --quiet") | crontab -7.3 模型加载缓慢优化
解决方案:
- 使用
--n-gpu-layers参数增加GPU加速层数 - 修改启动脚本
start.sh:python app.py --n-gpu-layers 40 --n_ctx 131072
8. 总结
通过本教程,您已经完成了:
- Qwen3.5-9B-GGUF模型的基础部署
- Nginx反向代理配置实现公网访问
- HTTPS安全加密配置
- 内网域名访问方案实施
- 完整的服务监控与管理体系
建议定期检查:
- SSL证书有效期(
certbot certificates) - 服务资源占用情况(
htop) - 模型推理日志(
service.log)
获取更多AI镜像
想探索更多AI镜像和应用场景?访问 CSDN星图镜像广场,提供丰富的预置镜像,覆盖大模型推理、图像生成、视频生成、模型微调等多个领域,支持一键部署。
