Installing and Configuring SearXNG

20 Oct 23


I use SearXNG as my search engine. It is sort of a front-end that queries a handful of other engines like Google, DuckDuckGo, and others. There are several public instances of SearXNG that anyone can use, but you can also host the software yourself.

Their install instructions are pretty straightforward. I installed nginx, then followed the SearXNG installation script process. I then went to the nginx specific instructions and kept getting "location directive not allowed here" from nginx. The SearXNG guide has you essentially put a "location" directive directly inside the "http" block of the nginx config files.. This leaves out the "server" block. Turns out, all you actually have to do is run the SearXNG install script with "nginx" instead of "all":

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

This makes all the necessary edits. I have SearXNG running on it's own domain, so I wanted to remove the /searxng from the URL. I changed the location directive to:

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;

    # see limiter.py
    uwsgi_param    HTTP_X_REAL_IP        $remote_addr;
    uwsgi_param    HTTP_X_FORWARDED_FOR  $proxy_add_x_forwarded_for;
}

Notice the different location specified and the removal of the script name parameter.

The last setup I did was block some annoying website that frequently come up in searches, but never just give a straight answer and are loaded with "you're using an adblocker" popups. I edited /etc/searxng/settings.yml, enabling the 'Hostname replace' plugin and adding some domains to the plugin's config section.

enabled_plugins:
  - 'Hash plugin'
  - 'Self Informations'
  - 'Tracker URL remover'
  - 'Ahmia blacklist'
  - 'Hostname replace'  # see hostname_replace configuration below
  # - 'Open Access DOI rewrite'

# plugins:
#   - only_show_green_results

hostname_replace:
#
#   # twitter --> nitter
#   '(www\.)?twitter\.com$': 'nitter.net'
  '(.*\.)?codegrepper\.com': false
  '(.*\.)?geeksforgeeks\.org': false

Note that the hostname_replace: line is commented out by default. And while we're here, changing the "instance_name: " parameter will change the text that the browser displays on the tab.




----------------
Comments
----------------