NGINX

Back to top

This section explains how to set up a SearXNG instance using the HTTP server nginx. If you have used the Installation Script and do not have any special preferences you can install the SearXNG site using searxng.sh:

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

If you have special interests or problems with setting up nginx, the following section might give you some guidance.

The nginx HTTP server

If nginx is not installed, install it now.

Ubuntu / debianArch LinuxFedora / RHEL

sudo -H apt-get install nginx
sudo -H pacman -S nginx-mainline
sudo -H systemctl enable nginx
sudo -H systemctl start nginx
sudo -H dnf install nginx
sudo -H systemctl enable nginx
sudo -H systemctl start nginx

Now at <http://localhost> you should see a Welcome to nginx! page, on Fedora you see a Fedora Webserver - Test Page. The test page comes from the default nginx server configuration. How this default site is configured, depends on the linux distribution:

Ubuntu / debianArch LinuxFedora / RHEL

less /etc/nginx/nginx.conf

There is one line that includes site configurations from:

include /etc/nginx/sites-enabled/*;
less /etc/nginx/nginx.conf

There is a configuration section named server:

server {
    listen       80;
    server_name  localhost;
    # ...
}
less /etc/nginx/nginx.conf

There is one line that includes site configurations from:

include /etc/nginx/conf.d/*.conf;

NGINX’s SearXNG site

Now you have to create a configuration file (searxng.conf) for the SearXNG site. If nginx is new to you, the nginx beginners guide is a good starting point and the Getting Started wiki is always a good resource to keep in the pocket.

Depending on what your SearXNG installation is listening on, you need a http or socket communication to upstream.

sockethttp

location /searxng {

    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_FORWARDED_PROTO  $scheme;
    uwsgi_param    HTTP_X_SCRIPT_NAME    /searxng;

    # see botdetection/trusted_proxies.py
    uwsgi_param    HTTP_X_REAL_IP        $remote_addr;
    uwsgi_param    HTTP_X_FORWARDED_FOR  $proxy_add_x_forwarded_for;
}

## To serve the static files via the HTTP server
#
## location /searxng/static/ {
##     alias /usr/local/searxng/searxng-src/searx/static/;
## }
location /searxng {

    proxy_pass http://127.0.0.1:8888;

    proxy_set_header   Host             $host;
    proxy_set_header   Connection       $http_connection;

    # see flaskfix.py
    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_set_header   X-Script-Name    /searxng;

    # see botdetection/trusted_proxies.py
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

    # proxy_buffering  off;
    # proxy_request_buffering off;
    # proxy_buffer_size 8k;

}

## To serve the static files via the HTTP server
#
## location /searxng/static/ {
##     alias /usr/local/searxng/searxng-src/searx/static/;
## }

The Installation Script installs the reference setup and a uWSGI setup that listens on a socket by default.

Ubuntu / debianArch LinuxFedora / RHEL

Create configuration at /etc/nginx/sites-available/ and place a symlink to sites-enabled:

sudo -H ln -s /etc/nginx/sites-available/searxng.conf \
              /etc/nginx/sites-enabled/searxng.conf

In the /etc/nginx/nginx.conf file, in the server section add a include directive:

server {
    # ...
    include /etc/nginx/default.d/*.conf;
    # ...
}

Create two folders, one for the available sites and one for the enabled sites:

mkdir -p /etc/nginx/default.d
mkdir -p /etc/nginx/default.apps-available

Create configuration at /etc/nginx/default.apps-available and place a symlink to default.d:

sudo -H ln -s /etc/nginx/default.apps-available/searxng.conf \
              /etc/nginx/default.d/searxng.conf

Create a folder for the available sites:

mkdir -p /etc/nginx/default.apps-available

Create configuration at /etc/nginx/default.apps-available and place a symlink to conf.d:

sudo -H ln -s /etc/nginx/default.apps-available/searxng.conf \
              /etc/nginx/conf.d/searxng.conf

Restart services:

Ubuntu / debianArch LinuxFedora / RHEL

sudo -H systemctl restart nginx
sudo -H service uwsgi restart searxng
sudo -H systemctl restart nginx
sudo -H systemctl restart uwsgi@searxng
sudo -H systemctl restart nginx
sudo -H touch /etc/uwsgi.d/searxng.ini

Disable logs

For better privacy you can disable nginx logs in /etc/nginx/nginx.conf.

http {
    # ...
    access_log /dev/null;
    error_log  /dev/null;
    # ...
}

Copyright © SearXNG team

Made with Furo

💾 🌐