Mustafa Can Yücel
blog-post-1

A Private Metasearch Engine: SearXNG

What is SearXNG?

SearXNG is a metasearch engine that aggregates the results of other search engines while not storing information about its users. The SearXNG project is driven by an open community, is open to any contributions, and is a non-profit project.

Why use it?

  • SearXNG may not offer you as personalized results as Google, but it doesn’t generate a profile about you.
  • SearXNG doesn’t care about what you search for, never shares anything with a third-party, and it can’t be used to compromise you.
  • SearXNG is free software, the code is 100% open, and everyone is welcome to make it better.
If you do care about privacy, want to be a conscious user, or otherwise believe in digital freedom, make SearXNG your default search engine or run it on your own server!

What is the difference between Searx and SearxNG?

SearXNG is designed for users who desire additional features and faster bug fixes. If you prefer simpler software with a stable experience, then Searx is recommended. SearXNG is a modified version of searx, created by a previous maintainer of searx. The fork was initiated because the majority of maintainers at the time believed that the proposed new features did not adequately prioritize user privacy. The primary concern lies with engine metrics.

SearxNG has rolling releases, dependencies are updated more frequently, and engines are fixed faster. It is easy to set up your own public instance and monitor its performance and metrics. It is simple to maintain as an instance administrator. As a user, it provides a prettier user interface and nicer experience. It also has the following advantages:

  • No need for Morty to proxy images, even on a public instance.
  • No need for Filtron to block bots, as there is now a built-in limiter.
  • A well-maintained Docker image, now also built for ARM64 and ARM/v7 architectures. (Alternatively, there are up-to-date installation scripts.)

How to Install

The search engine access will be over a reverse proxy. First and foremost, we will add an A record to our DNS keeper for search.example.com (or any other subdomain that you like) and point it to our server’s IP address.

Installing SearXNG

The installation of SearXNG is very easy using the docker image. We need docker and either docker-compose or docker compose cli plugin; if you followed my posts up to this point, both of these should be already installed on your system. If not, you can follow the instructions on the official docker website (Docker, Docker Compose).

Then we get the docker image from its repository to an appropriate location:

cd /usr/local
git clone https://github.com/searxng/searxng-docker.git
cd searxng-docker
If you plan to expose the search engine to the internet directly, you need to edit the .env file to set the hostname and email, but since we are going to use a reverse proxy, we keep it as is (which is empty except for comments by default).

We generate a secret key and save it to the searxng/settings.yml file:

sed -i "s|ultrasecretkey|$(openssl rand -hex 32)|g" searxng/settings.yml
We are going to leave the searxng/settings.yml file as is, but if you want to change the default settings, you can edit it now.

We need to change a single line in the docker-compose.yaml file. By default, it listens to port 8080 in localhost, but we want it to listen to another port that is unused. For this, we open this file and change the line 127.0.0.1:8080:8080 to 127.0.0.1:1111:8080 (I used 1111, you can choose any unused port that you like).

Finally, we can run the docker image in the background using the following command if you are using the docker compose cli plugin:

docker compose up -d
If you are using docker-compose:
docker-compose up -d

Configuring Caddy

We just add a reverse proxy to our Caddyfile (remember it is under /etc/caddy/, and don't forget to change the port number if you used a different one):

search.example.com {
    reverse_proxy http://localhost:1111 {
            header_up Host {upstream_hostport}
    }
}
Then we reload Caddy (remember to call this command in the directory where the Caddyfile is located):
sudo caddy reload

Starting SearXNG with systemd

The cloned repository has a systemd service file, so we can start it with systemd. You need to edit the content of WorkingDirectory in the searxng-docker.service file only if the installation path is different from /usr/local/searxng-docker:
cd /usr/local/searxng-docker
cp searxng-docker.service.template searxng-docker.service
systemctl enable $(pwd)/searxng-docker.service
systemctl start searxng-docker.service

Updating

Updating is very easy, we just need to pull the latest version of the docker image and restart the container (remember to change the commands if you are using docker-compose):

cd /usr/local/searxng-docker
docker compose pull
docker compose down
docker compose up