Setting up Nginx For Searx in freeBSD

This blog post was written by a freeBSD noob. I just wrote how I did it, which might not be the most efficient way possible :)

Installing packages

Install nginx

Install nginx with

sudo pkg install nginx

Install certbot

sudo pkg install #TODO

Configuring

configure nginx

Add nginx to rc.conf

#/etc/rc.conf
nginx_enable="YES"

and enable it

sudo service nginx start

Create a sites-enabled directory

sudo mkdir /usr/local/etc/nginx/sites-enabled

Create a conf file for searx

sudo touch /usr/local/etc/nginx/sites-enabled/searx.conf

Then we need to edit nginx.conf this way we are going to have the search engine in a subdomoin (for example searx.westofer.ga)

This file is going to be the homepage (in my example https://westofer.ga)

#/usr/local/etc/nginx/nginx.conf
worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    include /usr/local/etc/nginx/sites-enabled/*;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  YOUR-DOMAIN.COM;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            root   /usr/local/www/nginx;
            index  index.html index.htm;
        }
    }

Now for the searx.conf

server {
    listen 80;
    listen [::]:80;

    access_log /dev/null;
    error_log  /dev/null;

    root /var/www/subdomain.example.com;
    index index.html index.htm index.nginx-debian.html;

    server_name searx.domain.com;

    location / {

        proxy_pass http://localhost:8888; #port for searx
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Restarting nginx server

sudo service nginx restart

SSL certificate (https)

now you should see your website running in http://searx.domain.com, which is insecure, so we should upgrade to https with a SSL certificate from certbot.

there is guide for that here: How to use certbot in freeBSD with nginx