当前位置: 首页 > news >正文

anythingLLM结合searXNG实现联网搜索

1、docker-compose 部署searXNG

GitHub - searxng/searxng-docker: The docker-compose files for setting up a SearXNG instance with docker.

cd /usr/local
git clone https://github.com/searxng/searxng-docker.git
cd searxng-docker

2、修改 .env文件

# By default listen on https://localhost
# To change this:
# * uncomment SEARXNG_HOSTNAME, and replace <host> by the SearXNG hostname
# * uncomment LETSENCRYPT_EMAIL, and replace <email> by your email (require to create a Let's Encrypt certificate)

SEARXNG_HOSTNAME=172.16.50.25
LETSENCRYPT_EMAIL=381599113@qq.com

# Optional:
# If you run a very small or a very large instance, you might want to change the amount of used uwsgi workers and threads per worker
# More workers (= processes) means that more search requests can be handled at the same time, but it also causes more resource usage

# SEARXNG_UWSGI_WORKERS=4
# SEARXNG_UWSGI_THREADS=4

3、执行下面命令,生成  secret key 

sed -i "s|ultrasecretkey|$(openssl rand -hex 32)|g" searxng/settings.yml

4、修改 Caddyfile,防止 caddy 默认配置的 80端口冲突

{
	admin off
    http_port 8880
	log {
		output stderr
		format filter {
			# Preserves first 8 bits from IPv4 and 32 bits from IPv6
			request>remote_ip ip_mask 8 32
			request>client_ip ip_mask 8 32

			# Remove identificable information
			request>remote_port delete
			request>headers delete
			request>uri query {
				delete url
				delete h
				delete q
			}
		}
	}
}
172.16.50.25:8880 {


tls {$SEARXNG_TLS}

encode zstd gzip

@api {
	path /config
	path /healthz
	path /stats/errors
	path /stats/checker
}

@search {
	path /search
}

@imageproxy {
	path /image_proxy
}

@static {
	path /static/*
}

header {
	# CSP (https://content-security-policy.com)
	Content-Security-Policy "upgrade-insecure-requests; default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; form-action 'self' https://github.com/searxng/searxng/issues/new; font-src 'self'; frame-ancestors 'self'; base-uri 'self'; connect-src 'self' https://overpass-api.de; img-src * data:; frame-src https://www.youtube-nocookie.com https://player.vimeo.com https://www.dailymotion.com https://www.deezer.com https://www.mixcloud.com https://w.soundcloud.com https://embed.spotify.com;"

	# Disable some browser features
	Permissions-Policy "accelerometer=(),camera=(),geolocation=(),gyroscope=(),magnetometer=(),microphone=(),payment=(),usb=()"

	# Set referrer policy
	Referrer-Policy "no-referrer"

	# Force clients to use HTTPS
	Strict-Transport-Security "max-age=31536000"

	# Prevent MIME type sniffing from the declared Content-Type
	X-Content-Type-Options "nosniff"

	# X-Robots-Tag (comment to allow site indexing)
	X-Robots-Tag "noindex, noarchive, nofollow"

	# Remove "Server" header
	-Server
}

header @api {
	Access-Control-Allow-Methods "GET, OPTIONS"
	Access-Control-Allow-Origin "*"
}

route {
	# Cache policy
	header Cache-Control "max-age=0, no-store"
	header @search Cache-Control "max-age=5, private"
	header @imageproxy Cache-Control "max-age=604800, public"
	header @static Cache-Control "max-age=31536000, public, immutable"
}

# SearXNG (uWSGI)
reverse_proxy localhost:8080 {
	header_up X-Forwarded-Port {http.request.port}
	header_up X-Real-IP {http.request.remote.host}

	# https://github.com/searx/searx-docker/issues/24
	header_up Connection "close"
}
}

5、docker-compose配置文件

version: "3.7"

services:
  caddy:
    container_name: caddy
    image: docker.io/library/caddy:2-alpine
    network_mode: host
    restart: always
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy-data:/data:rw
      - caddy-config:/config:rw
    environment:
      - SEARXNG_HOSTNAME=${SEARXNG_HOSTNAME:-http://localhost}
      - SEARXNG_TLS=${LETSENCRYPT_EMAIL:-internal}
    cap_drop:
      - ALL
    cap_add:
      - NET_BIND_SERVICE
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "1"

  redis:
    container_name: redis
    image: docker.io/valkey/valkey:8-alpine
    command: valkey-server --save 30 1 --loglevel warning
    restart: always
    networks:
      - searxng
    volumes:
      - valkey-data2:/data
    cap_drop:
      - ALL
    cap_add:
      - SETGID
      - SETUID
      - DAC_OVERRIDE
    logging:
      driver: "json-file"
      options:
        max-size: "1m"
        max-file: "1"

  searxng:
    container_name: searxng
    image: docker.io/searxng/searxng:latest
    restart: always
    networks:
      - searxng
    ports:
      - "8080:8080"
    volumes:
      - ./searxng:/etc/searxng:rw
    environment:
      - SEARXNG_BASE_URL=https://${SEARXNG_HOSTNAME:-localhost}/
      - UWSGI_WORKERS=${SEARXNG_UWSGI_WORKERS:-4}
      - UWSGI_THREADS=${SEARXNG_UWSGI_THREADS:-4}
    cap_add:
      - CHOWN
      - SETGID
      - SETUID
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "1"

networks:
  searxng:

volumes:
  caddy-data:
  caddy-config:
  valkey-data2:

On the first run, you must remove cap_drop: - ALL from the docker-compose.yaml file for the searxng service to successfully create /etc/searxng/uwsgi.ini. This is necessary because the cap_drop: - ALL directive removes all capabilities, including those required for the creation of the uwsgi.ini file. After the first run, you should re-add cap_drop: - ALL to the docker-compose.yaml file for security reasons.

6、配置  settings.yml

项目默认的搜索返回的格式为 html 格式,在使用网络爬虫或其它形式的分析器调用 API 时,希望返回 json 格式,这时就需要修改返回格式。

添加以下内容

search:
  formats:
  - html
  - csv
  - json
  - rss

整体内容如下

# see https://docs.searxng.org/admin/settings/settings.html#settings-use-default-settings
use_default_settings: true
server:
  # base_url is defined in the SEARXNG_BASE_URL environment variable, see .env and docker-compose.yml
  secret_key: "58e0507b6a5428c2f87e26fc83509028f53a12daa1800448dcd7c47c19c7bb6e"  # change this!
  limiter: false  # can be disabled for a private instance
  image_proxy: true
ui:
  static_use_hash: true
redis:
  url: redis://redis:6379/0
  
search:
  formats:
  - html
  - csv
  - json
  - rss

配置参考 

Step by step installation — SearXNG Documentation (2025.3.22+5986629c6)

测试 json返回

http://172.16.50.25:8080/search?q=deepseek&format=json

7、anythingLLM配置 websearch

8、工作空间配置

9、使用

相关文章:

  • LeetCode Hot 100 - 子串 | 560.和为K的子数组、239.滑动窗口最大值、76.最小覆盖子串
  • 【Vue3入门1】03-Vue3的基本操作(下)
  • Cocos Creator Shader入门实战(五):材质的了解、使用和动态构建
  • 推荐一个智能抠图与背景替换工具,支持docker部署、API调用
  • go复习目录
  • 基于Sentinel-1A GRD洪涝淹没范围提取(SDWI阈值法和OSTU自动阈值法)
  • .NET 10 新的 JsonIgnoreCondition
  • Python Lambda 函数详解
  • 智慧高速,安全护航:视频监控平台助力高速公路高效运营
  • 知识分享导航
  • Jmeter简介、学习目标及安装启动
  • Maven下载以及项目创建(笔记)
  • 开发一款自然语言转sql的网页版数据库管理工具,不需要使用网上那些付费版,自己搭建一套数据库管理工具,免费开源
  • Unix 域套接字(本地套接字)
  • YOLOv12环境配置,手把手教你使用YOLOv12训练自己的数据集和推理(附YOLOv12网络结构图),全文最详细教程
  • 基于Spring Boot的产业园区智慧公寓管理系统的设计与实现(LW+源码+讲解)
  • 一区思路!
  • Java-模块二-1
  • Java 对 PDF 文件添加水印
  • 利用 MATLAB/Simulink 建立完整的控制系统模型,并进行阶跃响应和负载扰动响应仿真
  • 王毅谈中拉论坛第四届部长级会议重要共识
  • 梅花奖在上海丨陈丽俐“婺剧折戏专场”:文戏武做,武戏文唱
  • 王毅谈中拉论坛十年成果
  • 超新星|18岁冲击中超金靴,王钰栋的未来无限可能
  • 80后莆田市文旅局长马骏登台与杨宗纬合唱,“演唱会秒变旅游推介会”
  • 中国一直忽视欧盟经贸问题关切?外交部:事实证明中欧相互成就,共同发展