SearXNG Docker 部署教程(基于 1Panel)

_

一、环境要求

操作系统:Linux(Ubuntu / Debian 推荐)

管理面板:1Panel(支持 Docker Compose)

Docker ≥ 20.10

Docker Compose V2

Redis/Valkey(可选,推荐安装,用于限流 + 缓存,1Panel 应用商店一键部署)

二、目录结构

/opt/1panel/docker/compose/searxng/
├── docker-compose.yml          # 容器编排
├── .env                        # 环境变量(统一管理所有可变参数)
├── searxng/                    # 静态配置文件
│   ├── settings.yml
│   └── limiter.toml
└── data/searxng/               # 运行时缓存、临时数据(可定期清理)

三、配置文件

1. docker-compose.yml

# Docker Compose V2 | 适配1Panel网络
services:
  searxng:
    image: ${SEARXNG_IMAGE}
    container_name: ${SEARXNG_CONTAINER_NAME}
    restart: ${SEARXNG_RESTART_POLICY}

    networks:
      - 1panel-network

    ports:
      # 建议公网环境使用反向代理,仅监听127.0.0.1:${SEARXNG_HOST_PORT}:${SEARXNG_CONTAINER_PORT}
      - "${SEARXNG_HOST_PORT}:${SEARXNG_CONTAINER_PORT}"
// [!code fold:start]
    volumes:
      # 配置目录只读保护(修改配置需要重启容器)
      - ./searxng:/etc/searxng:ro
      # 可写缓存目录
      - ./data/searxng:/var/cache/searxng:rw

    environment:
      - SEARXNG_BASE_URL=${SEARXNG_BASE_URL}
      - UWSGI_WORKERS=${UWSGI_WORKERS}
      - UWSGI_THREADS=${UWSGI_THREADS}
      - SEARXNG_SECRET_KEY=${SEARXNG_SECRET_KEY}
      # 留空则自动关闭redis缓存/限流
      - SEARXNG_REDIS_URL=${SEARXNG_REDIS_URL}

    # 安全权限收紧
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - SETGID
      - SETUID

    # 资源限制,防止吃光服务器资源
    deploy:
      resources:
        limits:
          cpus: '1.2'
          memory: 768M
        reservations:
          memory: 256M

    # 健康检查,1Panel可识别容器状态
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://127.0.0.1:8080/healthz"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 20s

    # Docker日志轮转,防止日志爆满磁盘
    logging:
      driver: json-file
      options:
        max-size: ${LOG_MAX_SIZE}
        max-file: ${LOG_MAX_FILE}

# 使用1Panel外部网络(实现与Redis容器互通)
networks:
  1panel-network:
    external: true

2. .env

# ====================== 镜像与容器基础配置 ======================
# 生产建议锁定固定版本,不要使用latest
SEARXNG_IMAGE=searxng/searxng:latest
SEARXNG_CONTAINER_NAME=searxng
SEARXNG_RESTART_POLICY=unless-stopped

# ====================== 端口映射 ======================
SEARXNG_HOST_PORT=8088
SEARXNG_CONTAINER_PORT=8080
// [!code fold:start]
# ====================== 站点地址【重要】======================
# 公网域名部署改为 https://search.xxx.com/
SEARXNG_BASE_URL=http://localhost:8088

# 密钥生成命令:openssl rand -hex 32
SEARXNG_SECRET_KEY=REPLACE_WITH_YOUR_SECURE_KEY

# ====================== Redis / Valkey 配置 ======================
# 若无Redis,请清空值 SEARXNG_REDIS_URL=
# 格式:valkey://:密码@容器名:6379/0
SEARXNG_REDIS_URL=valkey://1panel-redis-oiqI:6379/0

# ====================== uWSGI进程调优(根据服务器CPU调整) ======================
UWSGI_WORKERS=4
UWSGI_THREADS=2

# ====================== Docker日志轮转 ======================
LOG_MAX_SIZE=10m
LOG_MAX_FILE=3

3. searxng/settings.yml

use_default_settings: true

general:
  instance_name: "我的SearXNG"
  debug: false
  privacypolicy_url: false

server:
  secret_key: "${SEARXNG_SECRET_KEY}"
  limiter: true                 # 限流依赖Redis
  image_proxy: true
  http_protocol_version: "1.1"
  request_timeout: 10.0
// [!code fold:start]
  # 反向代理可信网段(1Panel内网网段)
  trusted_proxies:
    - "127.0.0.0/8"
    - "172.16.0.0/12"
    - "192.168.0.0/16"

ui:
  static_use_hash: true
  theme: simple
  default_locale: "zh-Hans-CN"
  query_in_title: true
  center_alignment: true
  results_on_new_tab: false
  infinite_scroll: false
  search_on_category_select: true

search:
  safe_search: 0
  autocomplete: "baidu"
  default_lang: "zh-CN"
  languages:
    - "zh-CN"
    - "en"
  formats:
    - html
    - json
  scoring:
    method: linear
    profile: normal

# Redis缓存(启用后大幅提速,必须配置SEARXNG_REDIS_URL)
cache:
  type: redis
  expire: 3600

engines:
  # 百度网页搜索
  - name: baidu
    engine: baidu
    categories: [web, general]
    disabled: false
    timeout: 8.0
    max_results: 20

  # Bing必应(国内稳定)
  - name: bing
    engine: bing
    categories: [web, general, images]
    disabled: false
    timeout: 10.0
    max_results: 20
    params:
      region: "zh-CN"

  # 360搜索
  - name: 360search
    engine: 360search
    categories: [web, general]
    disabled: false
    timeout: 8.0

  # 搜狗极易验证码,默认关闭
  - name: sogou
    engine: sogou
    categories: [web, general]
    disabled: true
    timeout: 8.0

  # B站视频搜索
  - name: bilibili
    engine: bilibili
    categories: [videos]
    disabled: false
    timeout: 8.0

  # 海外引擎(国内网络默认禁用)
  - name: google
    engine: google
    disabled: true
  - name: duckduckgo
    engine: duckduckgo
    disabled: true
  - name: startpage
    engine: startpage
    disabled: true
  - name: qwant
    engine: qwant
    disabled: true
  - name: wikipedia
    engine: wikipedia
    disabled: true
  - name: brave
    engine: brave
    disabled: true
  - name: wikidata
    engine: wikidata
    disabled: true

preferences:
  lock:
    - language
    - locale

4. searxng/limiter.toml(完整版,修复反向代理 IP 识别)

# 限流、机器人检测配置
[botdetection]
ipv4_prefix = 24
ipv6_prefix = 48
# 可信代理网段(1Panel docker内网)
trusted_proxies = [
  "127.0.0.0/8",
  "::1",
  "172.16.0.0/12",
  "192.168.0.0/16"
]
// [!code fold:start]
[botdetection.ip_limit]
link_token = false
filter_link_local = false

# 内网免限流(可选,自用实例推荐开启)
[botdetection.ip_lists]
pass_ip = [
  "127.0.0.0/8",
  "192.168.0.0/16"
]
block_ip = []

四、部署步骤

第一步:创建目录并初始化权限

mkdir -p /opt/1panel/docker/compose/searxng/{searxng,data/searxng}
cd /opt/1panel/docker/compose/searxng

提示:所有配置文件放入对应文件夹内

第二步:修改关键参数

  1. .envSEARXNG_SECRET_KEY 使用命令生成替换

openssl rand -hex 32
  1. 确认 SEARXNG_REDIS_URL,没有 Redis 则清空变量值

  2. 公网域名部署务必修改 SEARXNG_BASE_URL

第三步:启动容器

docker compose down
docker compose up -d

第四步:查看日志验证

docker compose logs -f searxng

成功标志:日志输出 [INFO] Started worker

第五步:访问

内网直访:http:// 服务器 IP:8088

公网安全建议

不要直接暴露端口!使用 1Panel Nginx 反向代理 + HTTPS

Nginx 务必传递真实 IP 头:

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;

五、常见故障排查

问题 1:Redis 连接报错

  • 确认 Redis 容器加入 1panel-network

docker network connect 1panel-network 1panel-redis-xxx
  • searxng 新版同时支持 redis:// / valkey://

  • 无 Redis 环境:.env 设置 SEARXNG_REDIS_URL=,此时限流与缓存自动失效

问题 2:limiter.toml 格式报错

只保留上面提供完整配置,不要复制网上碎片化片段

问题 3:所有外部用户被限流(反向代理典型坑)

原因:limiter 无法读取真实客户端 IP

解决:

  1. nginx 添加 X-Forwarded 相关 header

  2. settings.yml 写入正确 trusted_proxies

  3. limiter.toml 补充 trusted_proxies

问题 4:提示 secret_key 未修改

确认 .env 密钥已替换,重启容器

问题 5:搜索无结果 / 频繁验证码

关闭不稳定搜索引擎(sogou/google 等)、适当调高 request_timeout

六、运维 & 性能优化建议

  1. 镜像策略:生产环境不要使用 latest,指定固定 tag,避免自动更新后配置不兼容

  2. 定期清理缓存

rm -rf /opt/1panel/docker/compose/searxng/data/searxng/*
docker compose restart searxng
  1. 资源调整:单核小内存机器调低UWSGI_WORKERS=2

  2. 备份:定期备份 searxng/ 配置文件夹

  3. API 使用:访问 http://ip:8088/search?q=关键词&format=json 获取 JSON 搜索结果

参考资料

AdGuard Home Docker Compose 模版2026-07-29
单源最短路径Dijkstra算法,零基础也能看懂的逻辑2026-07-31

评论区