使用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