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

使用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.dtcms.com/a/293520.html

相关文章:

  • AI聊天方案:vue+nodeJs+SSE
  • 变频器带动电机:全方位解析参数变化
  • MCP与企业数据集成:ERP、CRM、数据仓库的统一接入
  • 第一层nginx访问url如何透传到第二层nginx
  • OpenLayers 快速入门(九)Extent 介绍
  • Leetcode力扣解题记录--第240题(矩阵搜索)
  • 数据科学与大数据技术和统计学有什么区别?​
  • 关于针对 DT_REG 出现红色波浪线的问题(编译错误/IDE警告),以下是 精准解决方案,保持你的代码功能完全不变:
  • 【Linux-云原生-笔记】Haproxy相关
  • 基于Python(Django)+MongoDB实现的(Web)新闻采集和订阅系统
  • 模拟实现消息队列项目
  • 使用PEghost恢复系统(笔记版)
  • OpenEuler系统架构下编译redis的RPM包
  • [Mediatek] MTK openwrt-21.02 wifi 没启动问题
  • Android Multidex 完全解析:解决64K方法数限制
  • Java 虚拟线程在高并发微服务中的实战经验分享
  • 从0开始学习R语言--Day55--弹性网络
  • TDengine 的 HISTOGRAM() 函数用户手册
  • LabVIEW激光雷达障碍物识别
  • #C语言——学习攻略:操作符的探索(二)
  • 架构师--基于常见组件的微服务场景实战
  • VI Server 操控 LabVIEW 工程
  • DeepSeek Janus Pro本地部署与调用
  • 基于Trae IDE与MCP实现网页自动化测试的最佳实践
  • CI/CD与DevOps集成方法
  • 希尔排序cc
  • 无人机减震模块技术解析
  • Java冒泡排序的不同实现
  • 无人机吊舱减震球模块运行分析
  • 如何在Pico等Android头显中实现无人机低延迟RTMP全景巡检画面播放