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: instead of processing searches, 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 browsing and exploring the web incredibly convenient. 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 want their search queries associated with their name.

Searxng Install 04 Classified Information Example

One way to deal with this privacy issue is to install and host your own instance of SearXNG to ensure that only you will have access to your search 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 either be a computer in your home with a static IP address or a dedicated virtual private server (VPS) that you rent.
  • Root access to your machine: SearXNG requires you to install some system tools to configure and host it properly.

This tutorial 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.

Switch to the new user account by running su searxthen 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 the ports you allow to 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, allowing 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 to ensure your machine has the correct settings between system reboots.
  • Both ufw ensure that any current HTTP or HTTPS connection remains open for the duration of the session.

Cloning and Installing SearXNG

SearXNG developers provide a simple installer script that handles most of the complicated setup steps.

Searxng Installer 09 Searxng Github Page

Get this install 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, 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

You need to set up a web server that will serve SearXNG, because the search engine is just a process that takes requests and posts the results. Without a proper web server it is not possible to interact with and use SearXNG.

Searxng Install 12 Search engine running

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

Configuring Nginx

Create a new configuration file under “/etc/nginx/sites-available/”:

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

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 the 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 on your system.
  • 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”.
  • The 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.
  • 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

Creating an SSL certificate for your SearXNG instance ensures that every connection you make with your website is secure.

Searxng Install 14 Sample SSL Certificate

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

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/

Reload SearXNG and Nginx to apply and activate your configurations:

sudo systemctl reload nginx
sudo service uwsgi restart 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, because a Redis failure in SearXNG means it’s running in a non-SystemD system and its anti-bot filtering daemon isn’t running.

uninstall SearXNG by running the command sudo /home/$USER/searxng/utils/searxng.sh remove allto fix the problem and make sure you are using SystemD by running 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’re not sure what’s causing the issues. For example, I can access SearXNG’s debug screen by running sudo /home/$USER/searxng/utils/searxng.sh instance inspect.

Image credit: Isaac Quesada via Unsplashmodified by Ramces Red with 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