OpenWebUI 集成 SearXNG 实现本地大模型联网搜索配置指南
本地大模型通常面临知识截止日期固定的问题,无法获取实时信息。通过部署 SearXNG 元搜索引擎配合 OpenWebUI,可以有效解决这一问题。
1. 为什么需要 SearXNG?
OpenWebUI 内置的搜索引擎选项存在局限性:
- DuckDuckGo:对中文内容支持有限
- Google PSE:API 限制严格,免费版每日仅 100 次
- Bing:API 申请流程复杂
- Mojeek:响应速度慢
SearXNG 作为元搜索引擎的优势:
- 隐私保护:不跟踪用户,请求匿名化
- 高度可定制:支持百度、360、搜狗等国内引擎
- API 友好:提供 JSON 格式输出
- 自托管:完全控制服务可用性
2. SearXNG 部署详解
推荐使用 Docker Compose 方案进行部署。
2.1 环境准备与基础部署
确保服务器已安装 Docker 和 Docker Compose。
# 更新系统包
sudo apt update && sudo apt upgrade -y
# 安装 Docker(如果尚未安装)
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# 安装 Docker Compose
sudo apt install docker-compose-plugin -y
# 验证安装
docker --version
docker compose version
创建工作目录并获取配置文件:
mkdir -p ~/searxng-docker && cd ~/searxng-docker
git clone https://github.com/searxng/searxng-docker.git .
2.2 Docker Compose 配置优化
创建 docker-compose.yaml 文件:
version: "3.7"
services:
redis:
container_name: redis
image: docker.io/valkey/valkey:8-alpine
command: valkey-server --save 30 1 --loglevel warning
restart: unless-stopped
networks:
- searxng
volumes:
- valkey-data:/data
logging:
driver: "json-file"
options:
max-size: "1m"
max-file: "1"
searxng:
container_name: searxng
image: searxng/searxng:latest
restart: unless-stopped
networks:
- searxng
ports:
- "8080:8080"
volumes:
- ./searxng:/etc/searxng:rw
- ./engines:/usr/local/searxng/searx/engines:rw
environment:
- SEARXNG_BASE_URL=http://${SEARXNG_HOSTNAME:-localhost}:8080/
- UWSGI_WORKERS=${SEARXNG_UWSGI_WORKERS:-4}
- UWSGI_THREADS=${SEARXNG_UWSGI_THREADS:-4}
logging:
driver: "json-file"
options:
max-size: "1m"
max-file: "1"
networks:
searxng:
volumes:
valkey-data:
driver: local
driver_opts:
type: none
o: bind
device: /data/searxng-docker/redis
关键点说明:
- 移除了 Caddy 服务,内网部署直接访问端口更简单
- 持久化引擎目录,支持国内搜索引擎
- 使用 Valkey 替代 Redis,兼容性更好
- 使用自定义网络,方便后续与 OpenWebUI 容器通信
2.3 配置文件深度定制
修改 ./searxng/settings.yml 文件以支持国内搜索引擎:
use_default_settings: true
server:
secret_key: "你的安全密钥"
limiter: false
image_proxy: true
ui:
static_use_hash: true
redis:
url: redis://redis:6379/0
search:
formats:
- html
- json
engines:
- name: baidu
categories: [web, news, general]
engine: baidu
shortcut: bd
timeout: 9.0
disabled: false
enable_http: false
- name: 360search
categories: [web, news, general]
engine: 360search
shortcut: 360so
timeout: 9.0
disabled: false
enable_http: false
- name: sogou
categories: [web, news, general]
engine: sogou
shortcut: sg
timeout: 9.0
disabled: false
- name: google
engine: google
disabled: true
- name: bing
engine: bing
disabled: true
- name: duckduckgo
engine: duckduckgo
disabled: true
- name: startpage
engine: startpage
disabled: true
- name: wikipedia
engine: wikipedia
disabled: false
timeout: 15.0
- name: github
engine: github
disabled: false
shortcut: gh
提示:secret_key 需要自行生成,可使用命令 openssl rand -hex 32。Windows 用户可以使用 PowerShell 运行 OpenSSL 命令生成密钥。

