How to create a search engine with SearxNG

SearXNG is a powerful meta search engine that you can host anywhere. Unlike traditional search engines, SearXNG is an engine aggregator. This means that instead of processing searches on its own, it uses other engines to perform the search. Plus, SearXNG is incredibly lightweight and easy to set up, and you can host it on a system as simple as a Raspberry Pi!

Why Install SearXNG

Search engines make it easier to navigate and discover the web. However, using a public search engine comes at a price – modern search companies like Google use your search data to create a very accurate profile of you.

Searchxng Installer 03 Google Myactivity

This behavior may seem intrusive to people who want to keep their searches private and anonymous. For example, journalists who cover sensitive and controversial topics may not wish to associate their search queries with their names.

Searxng Install 04 Classified Information Example

One way to deal with this privacy issue is to install and host your own instance of SearXNG. This ensures that only you will have access to your research logs.

What you will need

SearXNG requires you to have a few things ready before you can install it:

  • A fully qualified domain name (FQDN): To use SearXNG, you need to host it through an appropriate web server with a domain.
  • A machine accessible from outside your home network: This can be either a computer in your home that has a static IP address or a dedicated virtual private server (VPS) that you currently rent.
  • Root access to your machine: This is because SearXNG requires you to install some system tools to configure and host it properly.

This tutorial only focuses on installing and configuring SearXNG on a Debian 11 VPS from DigitalOcean.

Searxng Installer 05 Digitalocean Droplet

Installing SearXNG dependencies

Before you can install SearXNG, you need to create a separate user account in your system:

sudo useradd -s /bin/bash -d /home/searx -m -G sudo searx
sudo passwd searx
Searxng Installer 06 Create New User

This allows you to isolate all commands and files when installing and configuring SearXNG. This can be especially useful if you intend to host the search engine on a VPS with multiple services.

Once done, you need to switch to the new user account by running su searx. From here you can now install all necessary dependencies for SearXNG:

sudo apt install git nginx iptables iptables-persistent ufw certbot python3-certbox-nginx
Searxng Install 07 Installation Dependencies

Configuring your firewall

Although not a necessary step, configuring your firewall ensures that any outside system will only be able to access ports allowed by you. This can help prevent any malicious actor from flooding your machine with endless requests.

Searxng Install 08 Install firewall rules

You can use both iptables and ufw to enable only the ports SearXNG needs:

sudo iptables -I INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
sudo iptables -I INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT
sudo netfilter-persistent save
sudo ufw allow 80
sudo ufw allow 443
  • Both iptables The commands create a new rule that accepts all new incoming HTTP and HTTPS connections to your machine. This, in turn, enables your system to serve the SearXNG web page to your users.
  • The netfilter-persistent The command saves and reloads any changes you make to your firewall. This ensures that your machine has the correct settings between system reboots.
  • Finally, both ufw The commands ensure that any current connection in HTTP and HTTPS remains open for the duration of the session.

Cloning and Installing SearXNG

The next thing you need to do is download and install SearXNG on your machine. The program developers offer a simple installation script that handles most of the complicated setup steps.

Searxng Installer 09 Searxng Github Page

You can get this installer script by cloning the program GitHub repository:

git clone https://github.com/searxng/searxng searxng && cd searxng
Searxng Install 10 Git Clone Repository

Once the cloning is complete, you can start the installation process:

sudo -H ./utils/searxng.sh install all

Although this process is largely automatic, there are cases where the script asks you to confirm the changes it makes. For example, when the SearXNG script prints a list of programs it is going to install, you would press Yes Continue.

Searxng Install 11 Prompt Installation Example

Configuring SearXNG

Once SearXNG is on your machine, you need to set up a web server that will serve it, because the search engine is just a process that takes queries and posts the results. This means that without a proper web server it is not possible to interact with and use SearXNG.

Searxng Install 12 Search engine running

At the moment, SearXNG officially supports Apache and Nginx. This section focuses on setting up SearXNG as a standalone service using Nginx.

Configuring Nginx

First, you need to create a new configuration file under “/etc/nginx/sites-available/”:

sudo nano /etc/nginx/sites-available/searxng

You then need to write a server block to the file that will contain the web server configuration. For example, here is a basic block I use for my SearXNG instance:

server {
 
    # Ports.
    listen 80;
    listen [::]:80;
 
    # Hostname.
    server_name yetanothersearxserver.xyz;
 
    # Logging.
    access_log /dev/null;
    error_log  /dev/null;
 
    # Searx Redirect.
    location / {
        uwsgi_pass unix:///usr/local/searxng/run/socket;
 
        include uwsgi_params;
 
        uwsgi_param    HTTP_HOST             $host;
        uwsgi_param    HTTP_CONNECTION       $http_connection;
 
        # see flaskfix.py
        uwsgi_param    HTTP_X_SCHEME         $scheme;
        uwsgi_param    HTTP_X_SCRIPT_NAME    /searxng;
 
        # see limiter.py
        uwsgi_param    HTTP_X_REAL_IP        $remote_addr;
        uwsgi_param    HTTP_X_FORWARDED_FOR  $proxy_add_x_forwarded_for;
 
    }
}
  • The listen The variables tell Nginx that this web server is broadcasting a service on port 80. It is important to change this value if you are already running a different virtual host in your system.
  • The server_name is a variable that must contain a fully qualified domain name that points to your machine. In my case, my webserver uses “yetanothersearxserver.xyz”.
  • Both access_log and error_log variables tell Nginx where to save information about your search queries. For example, setting it to “/dev/null” ensures that you don’t save any logs on the machine.
  • Finally, the location The block tells Nginx what to do each time a user connects to the web server.
Searxng Install 13 Nginx Setup Example

Installing SSL and activating SearXNG

The next thing you need to do is create an SSL certificate for your SearXNG instance. This ensures that every connection you make with your website is secure.

Searxng Install 14 Sample SSL Certificate

You can easily enable SSL for free by signing up with Allows you to encrypt‘s certbot. For example, I can run the following command to issue a certificate for my SearXNG host:

certbot --nginx yetanothersearxserver.xyz

You can now enable your website through Nginx by creating a symbolic link to the “sites_enabled” folder on the web server:

sudo ln -s /etc/nginx/sites-available/searx /etc/nginx/sites-enabled/

Once done, you need to reload SearXNG and Nginx to apply and activate your configurations:

sudo systemctl reload nginx
sudo service uwsgi restart searxng

Congratulations! Now you know how to build and host your own search engine using SearXNG.

Frequently Asked Questions

Is it possible to update SearXNG once I’ve installed it?

Yes! Although you cannot install SearXNG through a traditional package manager, it is possible to update and migrate the search engine from the command line. For example, you can update SearXNG by running the following command: sudo /home/$USER/searxng/utils/searxng.sh instance update.

The install script tells me that Redis is not available. Did my installation fail?

No. But this error will most likely make your SearXNG instance unstable. This is because a Redis failure in SearXNG means it is running in a non-SystemD system and its anti-bot filtering daemon is not running.

To resolve this issue, you need to uninstall SearXNG by running the following command: sudo /home/$USER/searxng/utils/searxng.sh remove all. Finally, you also need to make sure you’re using SystemD by running the following: sudo systemctl --version.

Is it possible to see what SearXNG is currently doing?

Yes! While SearXNG is a headless daemon that runs in the background, it is possible to check what it is currently doing. This is useful in cases where SearXNG is having issues and you are unsure what is causing the issues. For example, I can access SearXNG’s debug screen by running the following command: sudo /home/$USER/searxng/utils/searxng.sh instance inspect.

Image credit: Isaac Quesada via Unsplashedited by Ramces Red. Logo SearXNG and Wordmark. All screenshots by Ramces Red.

Was this article helpful?

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Brandon D. James