Black Friday: Save 10% for life on all of our VPS plans, now through Cyber Monday

10% off on selected plans for as long as you keep the service · new orders · up to 10 uses per customer · ends Dec 1, 2026, 12:00 AM EST.

See plans
Guideschevron_rightServers

Servers · 7 min read · Updated

How to Self-Host SearXNG for Private Search and AI Agents

To self-host SearXNG, download the official docker-compose.yml and .env from SearXNG's repository, set a secret key and bind it to the server itself, start it, then add json to the search formats in settings.yml so AI agents and scripts can call /search?q=…&format=json. Keep it private, behind a password or a VPN, unless you mean to run a public instance. It runs comfortably on a small VPS such as our smallest (6 GB, $37.50 a month).

Why Self-Host SearXNG for AI

Agents and AI chat apps need web search to answer questions about anything recent. Hosted search APIs usually bill per query and see every query; your own SearXNG answers in JSON from many engines at once, with no per-query bill. Run it on the same server as your AI chat, n8n workflows or agent and they reach it at http://127.0.0.1:8080.

1. Download the Compose Files

On Ubuntu 24.04, secure the server and install Docker. Then, as in SearXNG's Docker guide:

mkdir ~/searxng && cd ~/searxng
curl -fsSL -O https://raw.githubusercontent.com/searxng/searxng/master/container/docker-compose.yml \
  -O https://raw.githubusercontent.com/searxng/searxng/master/container/.env.example
cp -i .env.example .env

2. Set the Secret and Bind It Locally

echo "SEARXNG_HOST=127.0.0.1" >> .env
echo "SEARXNG_SECRET=$(openssl rand -hex 32)" >> .env
docker compose up -d
docker compose ps        # searxng-core and searxng-valkey running

SEARXNG_SECRET sets the server's secret key, which must not stay at its example value. SEARXNG_HOST=127.0.0.1 publishes port 8080 on the server itself only; without it, Docker opens the port to the internet past ufw (see why ufw does not block Docker ports). For a fixed version instead of latest, set SEARXNG_VERSION in the same file.

3. Turn On the JSON API

The first start writes core-config/settings.yml. Edit it so the search section lists JSON among its formats:

search:
  formats:
    - html
    - json
docker compose restart core
curl -s 'http://127.0.0.1:8080/search?q=searxng&format=json' | head -c 400

The API answers on /search (or /) by GET or POST, with the query in q (search API docs). An agent's search tool can be this short:

import requests

def web_search(query: str, n: int = 5):
    r = requests.get("http://127.0.0.1:8080/search",
                     params={"q": query, "format": "json"}, timeout=20)
    r.raise_for_status()
    return [(x["title"], x["url"]) for x in r.json()["results"][:n]]

4. Reach It From Elsewhere

Apps on the same server need nothing more. For your own browser or tools on other servers, either join them over WireGuard or our private network, or put Caddy in front with HTTPS and a password. Point an A record at the server, allow ports 80 and 443, then:

sudo apt install -y caddy
caddy hash-password          # type a password, copy the hash
sudo tee /etc/caddy/Caddyfile >/dev/null <<'EOF'
search.example.com {
    basic_auth {
        you PASTE-THE-HASH-HERE
    }
    reverse_proxy 127.0.0.1:8080
}
EOF
sudo systemctl reload caddy

A public instance is a different job: it needs SearXNG's limiter (limiter: true in the server section, backed by the Valkey container already running) and public_instance: true, as described in the limiter docs.

Keeping It Working

  • Engines can push back. Every query goes out from your server's address, and search engines may slow down or challenge an address sending many automated queries. Cache results in your agent and keep the volume reasonable.
  • Updates: docker compose pull && docker compose up -d. Engines change their pages often and SearXNG follows quickly, so update regularly.
  • Backups: only core-config/ and .env hold anything you wrote.

Common Questions

  • What is SearXNG?

    A free, open-source metasearch engine: it sends your query to many search engines, merges the results and shows them without tracking you or building a profile. Self-hosted, it also gives AI tools a search API you control.

  • Why does SearXNG return 403 Forbidden for format=json?

    The JSON format is off by default. Add json to the formats list in the search section of settings.yml and restart the container; requests for a format that is not enabled get 403.

  • Does SearXNG need Valkey or Redis?

    Only for the limiter, the bot protection a public instance needs. The official Docker Compose file runs Valkey next to SearXNG anyway, so turning the limiter on later needs no extra service.

  • Can I use searxng-docker?

    Not for new installs. The searxng-docker repository was archived in March 2026 and points to the Docker Compose setup in SearXNG's own documentation, which this guide follows.

Plans and prices

VPS Plans

KVM servers with full root access: a private search API for your AI tools.

See all plans
  • Bronze

    3 vCPU · 6 GB RAM · 75 GB NVMe

    2 TB transfer

    $37.50/mo

    Configure inAshburnDallas
  • Silver

    4 vCPU · 8 GB RAM · 100 GB NVMe

    4 TB transfer

    $46.50/mo

    Configure inAshburnDallas
  • Gold

    6 vCPU · 12 GB RAM · 150 GB NVMe

    6 TB transfer

    $60.00/mo

    Configure inAshburnDallas
  • Diamond

    8 vCPU · 16 GB RAM · 200 GB NVMe

    8 TB transfer

    $73.50/mo

    Configure inAshburnDallas

Network port: 10 Gbps in Ashburn, VA, 50 Gbps in Dallas, TX. Pick the location when you configure.

Keep Reading

All guides