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

使用Docker搭建SearXNG搜索引擎

1、安装Docker

# 安装Docker
https://docs.docker.com/get-docker/# 安装Docker Compose
https://docs.docker.com/compose/install/# CentOS安装Docker
https://mp.weixin.qq.com/s/nHNPbCmdQs3E5x1QBP-ueA

2、安装SearXNG

详见:
https://docs.searxng.org/admin/installation-docker.html
https://github.com/searxng/searxng-docker

创建目录:

mkdir searxng
cd searxng

下载:

wget https://github.com/searxng/searxng-docker/archive/refs/heads/master.zip

解压:

# 安装zip、unzip
# yum install -y zip unzip# 解压
unzip master.zip

切换目录:

cd searxng-docker-master

查看.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=<host>
# LETSENCRYPT_EMAIL=<email>

备份.env文件:

cp .env .env-bak

修改.env文件:

# 指定域名或ip,
# 假设当前ip为192.168.186.128,端口3000,供外网访问
sed -i 's/# SEARXNG_HOSTNAME=<host>/SEARXNG_HOSTNAME=http:\/\/192.168.186.128:3000/g' .env

查看Caddyfile文件:

{admin offlog {output stderr
format filter {
# Preserves first 8 bits from IPv4 and 32 bits from IPv6request>remote_ip ip_mask 8 32request>client_ip ip_mask 8 32# Remove identificable informationrequest>remote_port deleterequest>headers deleterequest>uri query {
delete url
delete h
delete q}}}servers {client_ip_headers X-Forwarded-For X-Real-IP# Allow the following IP to passthrough the "X-Forwarded-*" headers to SearXNG
# https://caddyserver.com/docs/caddyfile/options#trusted-proxiestrusted_proxies static private_rangestrusted_proxies_strict}
}{$SEARXNG_HOSTNAME}tls {$SEARXNG_TLS}encode zstd gzip@api {path /configpath /healthzpath /stats/errorspath /stats/checker
}@static {path /static/*
}@imageproxy {path /image_proxy
}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:; font-src 'self'; frame-ancestors 'self'; base-uri 'self'; connect-src 'self'; img-src * data:; frame-src https:;"# Disable browser featuresPermissions-Policy "accelerometer=(),camera=(),geolocation=(),gyroscope=(),magnetometer=(),microphone=(),payment=(),usb=()"# Only allow same-origin requestsReferrer-Policy "same-origin"# Prevent MIME type sniffing from the declared Content-TypeX-Content-Type-Options "nosniff"# Comment header to allow indexing by search enginesX-Robots-Tag "noindex, nofollow, noarchive, nositelinkssearchbox, nosnippet, notranslate, noimageindex"# Remove "Server" header-Server
}header @api {Access-Control-Allow-Methods "GET, OPTIONS"Access-Control-Allow-Origin "*"
}route {
# Cache policyheader Cache-Control "no-cache"header @static Cache-Control "public, max-age=30, stale-while-revalidate=60"header @imageproxy Cache-Control "public, max-age=3600"
}# SearXNG
reverse_proxy localhost:8080

备份Caddyfile文件:

cp Caddyfile Caddyfile-bak

修改Caddyfile文件:

sed -i 's/admin off/#admin off\n        http_port 3000\n        auto_https off/g' Caddyfile
sed -i 's/tls {$SEARXNG_TLS}/#tls {$SEARXNG_TLS}/g' Caddyfile
sed -i 's/Content-Security-Policy/#Content-Security-Policy/g' Caddyfile

查看searxng/settings.yml文件:

# 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.ymlsecret_key: "ultrasecretkey"  # change this!limiter: false  # enable this when running the instance for a public usage on the internetimage_proxy: true
redis:url: redis://redis:6379/0

备份searxng/settings.yml文件:

cp searxng/settings.yml searxng/settings.yml-bak

修改searxng/settings.yml文件:

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

查看docker-compose.yaml文件:

version: "3.7"services:caddy:container_name: caddyimage: docker.io/library/caddy:2-alpinenetwork_mode: hostrestart: unless-stoppedvolumes:- ./Caddyfile:/etc/caddy/Caddyfile:ro- caddy-data:/data:rw- caddy-config:/config:rwenvironment:- SEARXNG_HOSTNAME=${SEARXNG_HOSTNAME:-http://localhost}- SEARXNG_TLS=${LETSENCRYPT_EMAIL:-internal}logging:driver: "json-file"options:max-size: "1m"max-file: "1"redis:container_name: redisimage: docker.io/valkey/valkey:8-alpinecommand: valkey-server --save 30 1 --loglevel warningrestart: unless-stoppednetworks:- searxngvolumes:- valkey-data2:/datalogging:driver: "json-file"options:max-size: "1m"max-file: "1"searxng:container_name: searxngimage: docker.io/searxng/searxng:latestrestart: unless-stoppednetworks:- searxngports:- "127.0.0.1:8080:8080"volumes:- ./searxng:/etc/searxng:rw- searxng-data:/var/cache/searxng:rwenvironment:- SEARXNG_BASE_URL=https://${SEARXNG_HOSTNAME:-localhost}/logging:driver: "json-file"options:max-size: "1m"max-file: "1"networks:searxng:volumes:caddy-data:caddy-config:valkey-data2:searxng-data:

备份docker-compose.yaml文件:

cp docker-compose.yaml docker-compose.yaml-bak

修改docker-compose.yaml文件:

services:caddy:container_name: searxng-caddyimage: caddy:2-alpinenetwork_mode: hostrestart: unless-stoppedvolumes:- ./Caddyfile:/etc/caddy/Caddyfile:ro- ./caddy-data:/data:rw- ./caddy-config:/config:rwenvironment:- SEARXNG_HOSTNAME=${SEARXNG_HOSTNAME}logging:driver: "json-file"options:max-size: "1m"max-file: "1"redis:container_name: searxng-redisimage: valkey/valkey:8-alpinecommand: valkey-server --save 30 1 --loglevel warningrestart: unless-stoppednetworks:- searxngvolumes:- ./valkey-data2:/datalogging:driver: "json-file"options:max-size: "1m"max-file: "1"searxng:container_name: searxngimage: searxng/searxng:latestrestart: unless-stoppednetworks:- searxngports:- "127.0.0.1:8080:8080"volumes:- ./searxng:/etc/searxng:rw- ./searxng-data:/var/cache/searxng:rwenvironment:- SEARXNG_BASE_URL=${SEARXNG_HOSTNAME}logging:driver: "json-file"options:max-size: "1m"max-file: "1"networks:searxng:
说明:使用caddy做反向代理
假设ip为192.168.186.128,caddy默认端口80,searxng默认端口8080
在浏览器访问192.168.186.128:80如果将caddy端口改成3000,那么在浏览器访问192.168.186.128:3000

创建并启动容器:

docker-compose up -d

查看容器列表:

docker ps

查看容器日志:

# Caddy容器: 
docker logs -f searxng-caddy# SearXNG容器: 
docker logs -f searxng# Valkey容器: 
docker logs -f searxng-redis

停止并销毁容器:

docker-compose down

删除目录:

rm -rf ./caddy-data ./caddy-config ./valkey-data2 ./searxng-data

3、浏览器访问

假设当前ip为192.168.186.128
浏览器访问:http://192.168.186.128:8080

4、详见

https://docs.searxng.org/
https://github.com/searxng/searxng
https://github.com/searxng/searxng-docker
https://mp.weixin.qq.com/s/04sosQUYlnabyC2fa-5PIA
http://www.xdnf.cn/news/16209.html

相关文章:

  • 直播一体机技术方案解析:基于RK3588S的硬件架构特性​
  • 地理类专业选择指南:地理科学/测绘工程/遥感科学与技术
  • 基于LNMP分布式个人云存储
  • Docker详解及实战
  • 274款古装人物头像
  • 20250704-基于强化学习在云计算环境中的虚拟机资源调度研究
  • DeepSeek 助力 Vue3 开发:打造丝滑的日历(Calendar),日历_家庭维护示例(CalendarView01_31)
  • 性能测试-jmeter实战5
  • 【无标题】word 中的中文排序
  • 字节 AI 编辑器 Trae 2.0 SOLO 出道! 国际版不充分指南及与国内版的对比
  • 腾讯云推出CodeBuddy:革新AI全栈开发体验
  • Xorg占用显卡内存问题和编译opencv GPU版本
  • docker安装minio及配置禁止列出目录文件
  • 时序数据库主流产品概览
  • 分布式电商系统:缓存策略、负载均衡与容灾方案
  • 一款基于 WPF 开源、功能全面的串口调试工具
  • YOLO12论文阅读:Attention-Centric Real-Time Object Detectors
  • Python关于pandas的基础知识
  • Springboot和postman的使用
  • torchvision.transforms 与 MONAI 数据增强的异同
  • 华为视觉算法面试30问全景精解
  • 网易视觉算法面试30问全景精解
  • C++ 模板库map数据结构的概念和使用案例
  • 板凳-------Mysql cookbook学习 (十二--------5)
  • 鸿蒙卡片开发保姆级教程
  • Java 线程池详解:从原理到实战,彻底掌握并发编程核心组件
  • Baumer工业相机堡盟工业相机如何通过YoloV8深度学习模型实现水下鱼类识别(C#代码,UI界面版)
  • 【机器学习深度学习】微调量化与模型导出量化:区分与应用
  • 数字护网:一次深刻的企业安全体系灵魂演练
  • JavaScript 03 严格检查模式Strict字符串类型详解