searxng AI搜索能力

验证

docker exec -it open-webui curl "http://searxng:8080/search?q=hello"

docker-compose.yml

services:
  searxng:
    image: searxng/searxng:2026.6.30-d115c61a7
    container_name: searxng
    volumes:
      - ./data/etc:/etc/searxng:rw
      - ./data/cache:/var/cache/searxng:rw
    networks:
      - ghost_net
    dns:                        # <-- ADD THIS BLOCK
      - 1.1.1.1                 # Cloudflare DNS
      - 8.8.8.8                 # Google DNS
    ports:["0.0.0.0:60001:8080"] # 单独私有化web入口
    restart: unless-stopped
    logging:
      driver: "json-file"
      options:
        max-size: "1m"
        max-file: "1"
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - SETGID
      - SETUID
      - DAC_OVERRIDE
    deploy:
      resources:
        limits:
          memory: 512M

networks:
  ghost_net:
    external: true

nginx.conf

# ── JSON API 鉴权跳过 ────────────────────────────────────────────
map "$arg_format$arg_key" $searxng_auth {
    default "oauth";
    "json secretkeyxxxxxx" "bypass";
}

# ── HTTP → HTTPS ────────────────────────────────────────────────
server {
    listen 80;
    server_name searxng.atibm.com;
    return 301 https://$host$request_uri;
}

# ── HTTPS ────────────────────────────────────────────────────────
server {
    listen 443 ssl;
    server_name searxng.atibm.com;
    ssl_certificate     /etc/letsencrypt/live/ghost.atibm.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/ghost.atibm.com/privkey.pem;

    # ═══ JSON API 直通(内部跳转目标)═══
    location @searxng_bypass {
        proxy_pass http://searxng:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_http_version 1.1;
        proxy_cache off;
        proxy_buffering off;
        proxy_read_timeout 60s;
    }

    location /oauth2/ {
        proxy_pass http://hermes-oauth:4180;
        proxy_set_header Host hermes.atibm.com;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    # ═══ 主入口 ═══
    location / {
        # key 匹配 → 返回 418 → 内部跳转到 @searxng_bypass(绕过 OAuth)
        error_page 418 = @searxng_bypass;
        if ($searxng_auth = bypass) { return 418; }

        # 常规请求 → OAuth 验证
        auth_request /oauth2/auth;
        error_page 401 =302 /oauth2/start?rd=$scheme://$host$request_uri;

        proxy_pass http://searxng:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_cache off;
        proxy_buffering off;
        proxy_read_timeout 60s;
    }
}

setttings.yml

无指定user运行时,如果setting文件权限还报错,则需要修改文件权限
sudo chown 1001:1001 /data/etc/settings.yml
# 继承机制
use_default_settings:
  engines:
    remove:
      - wikidata     # arm服务器IP被屏蔽了,所以移除
      - ahmia
      - torch
      - aol          # arm服务器IP被屏蔽了
      - karmasearch  # arm服务器IP被屏蔽了
      - duckduckgo   # <-- 新增:这家机房IP秒弹验证码,踢掉
      - startpage    # <-- 新增:这家机房IP秒弹验证码,踢掉      

server:
  secret_key: "3e697f55ba6ec3fc98b36e06fcbac788cb09051b53877cabffcf0c2b44c468af" # 禁止使用默认key, openssl rand -hex 32

search:
  formats:
    - html
    - json
    
# 添加以下配置,彻底关闭实名/IP请求头和机器人检查,专为大模型联网设计
enabled_plugins:
  - 'Tracker Extractor plugin'
  
botdetection:
  ip_limit:
    link_token: false
    block_ip: false          # 关闭 IP 限制

接入open-webui

环境变量
      # --- 联网搜索 ---
      - ENABLE_RAG_WEB_SEARCH=True
      - RAG_WEB_SEARCH_ENGINE=searxng
      - SEARXNG_QUERY_URL=http://searxng:8080/search?q=<query>
      - RAG_WEB_SEARCH_RESULT_COUNT=3
      - RAG_WEB_SEARCH_CONCURRENT_REQUESTS=10

问题修复

  • 403 Forbidden(SearXNG 拒绝 JSON)

    sudo sed -i '/^[[:space:]]\+formats:/a \    - json' data/etc/settings.yml
    
    openwebui 出现这个日志表示搜索链路通了
    Fetching pages: 100%|##########| 8/8 [00:06<00:00,  1.20it/s]
  • 解决嵌入模型 NoneType 错误(RAG 功能依赖)

    具体报错
    embedding_function.encode()
    AttributeError: 'NoneType' object has no attribute 'encode'
    
    open-webui 设置 → 嵌入 选择一个可用的嵌入模型(推荐 bge-small-en-v1.5 或 all-MiniLM-L6-v2)
    勾选 绕过嵌入和检索
    设置完,重建索引