Skip to content

Commit ac56920

Browse files
authored
Merge pull request #851 from andrewbbaek/main
docs: Update SearXNG Web Search Guide for Docker Setup
2 parents e45855f + 9799fb4 commit ac56920

File tree

2 files changed

+60
-145
lines changed

2 files changed

+60
-145
lines changed

docs/features/web-search/searxng.md

Lines changed: 60 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ To configure SearXNG optimally for use with Open WebUI, follow these steps:
2121

2222
**Step 1: `git clone` SearXNG Docker and navigate to the folder:**
2323

24-
1. Create a New Directory `searxng-docker`
24+
1. Clone the repository `searxng-docker`
2525

26-
Clone the searxng-docker repository. This folder will contain your SearXNG configuration files. Refer to the [SearXNG documentation](https://docs.searxng.org/) for configuration instructions.
26+
Clone the searxng-docker repository. This will create a new directory called `searxng-docker`, which will contain your SearXNG configuration files. Refer to the [SearXNG documentation](https://docs.searxng.org/) for configuration instructions.
2727

2828
```bash
2929
git clone https://github.com/searxng/searxng-docker.git
3030
```
3131

32-
Navigate to the `searxng-docker` repository:
32+
Navigate to the `searxng-docker` repository, and run all commands from there:
3333

3434
```bash
3535
cd searxng-docker
@@ -49,7 +49,7 @@ cd searxng-docker
4949

5050
# * uncomment LETSENCRYPT_EMAIL, and replace <email> by your email (require to create a Let's Encrypt certificate)
5151

52-
SEARXNG_HOSTNAME=localhost:8080/
52+
SEARXNG_HOSTNAME=localhost
5353

5454
# LETSENCRYPT_EMAIL=<email>
5555

@@ -68,22 +68,34 @@ SEARXNG_HOSTNAME=localhost:8080/
6868

6969
3. Remove the `localhost` restriction by modifying the `docker-compose.yaml` file:
7070

71+
If port 8080 is already in use, change `0.0.0.0:8080` to `0.0.0.0:[available port]` in the command before running it.
72+
73+
Run the appropriate command for your operating system:
74+
75+
- **Linux**
76+
```bash
77+
sed -i 's/127.0.0.1:8080/0.0.0.0:8080/' docker-compose.yaml
78+
```
79+
80+
- **macOS**:
7181
```bash
72-
sed -i "s/127.0.0.1:8080/0.0.0.0:8080/"
82+
sed -i '' 's/127.0.0.1:8080/0.0.0.0:8080/' docker-compose.yaml
7383
```
7484

7585
**Step 4: Grant Necessary Permissions**
7686

7787
4. Allow the container to create new config files by running the following command in the root directory:
7888

7989
```bash
80-
sudo chmod a+rwx searxng-docker/searxng
90+
sudo chmod a+rwx searxng
8191
```
8292

8393
**Step 5: Create a Non-Restrictive `limiter.toml` File**
8494

8595
5. Create a non-restrictive `searxng-docker/searxng/limiter.toml` config file:
8696

97+
*If the file already exists, append the missing lines to it.*
98+
8799
<!-- markdownlint-disable-next-line MD033 -->
88100
<details>
89101
<!-- markdownlint-disable-next-line MD033 -->
@@ -112,172 +124,74 @@ pass_ip = []
112124
6. Delete the default `searxng-docker/searxng/settings.yml` file if it exists, as it will be regenerated on the first launch of SearXNG:
113125

114126
```bash
115-
rm searxng-docker/searxng/settings.yml
127+
rm searxng/settings.yml
116128
```
117129

118130
**Step 7: Create a Fresh `settings.yml` File**
119131

120-
:::note
121-
122-
On the first run, you must remove `cap_drop: - ALL` from the `docker-compose.yaml` file for the `searxng` service to successfully create `/etc/searxng/uwsgi`.ini. This is necessary because the `cap_drop: - ALL` directive removes all capabilities, including those required for the creation of the `uwsgi.ini` file. After the first run, you should re-add `cap_drop: - ALL` to the `docker-compose.yaml` file for security reasons.
123-
124-
:::
125-
126132
7. Bring up the container momentarily to generate a fresh settings.yml file:
127133

134+
If you have multiple containers running with the same name, such as caddy, redis, or searxng, you need to rename them in the docker-compose.yaml file to avoid conflicts.
135+
128136
```bash
129137
docker compose up -d ; sleep 10 ; docker compose down
130138
```
131139

132-
**Step 8: Add Formats and Update Port Number**
133-
134-
8. Add HTML and JSON formats to the `searxng-docker/searxng/settings.yml` file:
140+
After the initial run, add `cap_drop: - ALL` to the `docker-compose.yaml` file for security reasons.
135141

136-
```bash
137-
sed -i 's/formats: \[\"html\"\/]/formats: [\"html\", \"json\"]/' searxng-docker/searxng/settings.yml
138-
```
142+
If Open WebUI is running in the same Docker network as Searxng, you may remove the `0.0.0.0` and only specify the port mapping. In this case, Open WebUI can access Searxng directly using the container name.
139143

140-
Generate a secret key for your SearXNG instance:
144+
<details>
145+
<summary>docker-compose.yaml</summary>
141146

142-
```bash
143-
sed -i "s|ultrasecretkey|$(openssl rand -hex 32)|g" searxng-docker/searxng/settings.yml
147+
```yaml
148+
searxng:
149+
container_name: searxng
150+
image: docker.io/searxng/searxng:latest
151+
restart: unless-stopped
152+
networks:
153+
- searxng
154+
ports:
155+
- "0.0.0.0:8080:8080" # use 8080:8080 if containers are in the same Docker network
156+
volumes:
157+
- ./searxng:/etc/searxng:rw
158+
- searxng-data:/var/cache/searxng:rw
159+
environment:
160+
- SEARXNG_BASE_URL=https://${SEARXNG_HOSTNAME:-localhost}/
161+
logging:
162+
driver: "json-file"
163+
options:
164+
max-size: "1m"
165+
max-file: "1"
166+
cap_drop:
167+
- ALL
144168
```
145169
146-
Windows users can use the following powershell script to generate the secret key:
170+
</details>
147171
148-
```powershell
149-
$randomBytes = New-Object byte[] 32
150-
(New-Object Security.Cryptography.RNGCryptoServiceProvider).GetBytes($randomBytes)
151-
$secretKey = -join ($randomBytes | ForEach-Object { "{0:x2}" -f $_ })
152-
(Get-Content searxng-docker/searxng/settings.yml) -replace 'ultrasecretkey', $secretKey | Set-Content searxng-docker/searxng/settings.yml
153-
```
172+
**Step 8: Add Formats**
154173
155-
Update the port number in the `server` section to match the one you set earlier (in this case, `8080`):
174+
8. Add HTML and JSON formats to the `searxng-docker/searxng/settings.yml` file:
156175

176+
- **Linux**
157177
```bash
158-
sed -i 's/port: 8080/port: 8080/' searxng-docker/searxng/settings.yml
178+
sed -i 's/- html/- html\n - json/' searxng/settings.yml
159179
```
160180

161-
Change the `bind_address` as desired:
162-
181+
- **macOS**
163182
```bash
164-
sed -i 's/bind_address: "0.0.0.0"/bind_address: "127.0.0.1"/' searxng-docker/searxng/settings.yml
165-
```
166-
167-
#### Configuration Files
168-
169-
#### searxng-docker/searxng/settings.yml (Extract)
170-
171-
The default `settings.yml` file contains many engine settings. Below is an extract of what the default `settings.yml` file might look like:
172-
173-
<!-- markdownlint-disable-next-line MD033 -->
174-
<details>
175-
<!-- markdownlint-disable-next-line MD033 -->
176-
<summary>searxng-docker/searxng/settings.yml</summary>
177-
178-
```yaml
179-
180-
# see https://docs.searxng.org/admin/settings/settings.html#settings-use-default-settings
181-
use_default_settings: true
182-
183-
server:
184-
# base_url is defined in the SEARXNG_BASE_URL environment variable, see .env and docker-compose.yml
185-
secret_key: "ultrasecretkey" # change this!
186-
limiter: true # can be disabled for a private instance
187-
image_proxy: true
188-
port: 8080
189-
bind_address: "0.0.0.0"
190-
191-
ui:
192-
static_use_hash: true
193-
194-
search:
195-
safe_search: 0
196-
autocomplete: ""
197-
default_lang: ""
198-
formats:
199-
- html
200-
- json # json is required
201-
# remove format to deny access, use lower case.
202-
# formats: [html, csv, json, rss]
203-
redis:
204-
# URL to connect redis database. Is overwritten by ${SEARXNG_REDIS_URL}.
205-
# https://docs.searxng.org/admin/settings/settings_redis.html#settings-redis
206-
url: redis://redis:6379/0
183+
sed -i '' 's/- html/- html\n - json/' searxng/settings.yml
207184
```
208185

209-
The port in the settings.yml file for SearXNG should match that of the port number in your docker-compose.yml file for SearXNG.
210-
211-
</details>
212-
213-
**Step 9: Update `uwsgi.ini` File**
214-
215-
9. Ensure your `searxng-docker/searxng/uwsgi.ini` file matches the following:
216-
217-
<!-- markdownlint-disable-next-line MD033 -->
218-
<details>
219-
<!-- markdownlint-disable-next-line MD033 -->
220-
<summary>searxng-docker/searxng/uwsgi.ini</summary>
221-
222-
```ini
223-
[uwsgi]
224-
225-
# Who will run the code
226-
uid = searxng
227-
gid = searxng
228-
229-
# Number of workers (usually CPU count)
230-
231-
# default value: %k (= number of CPU core, see Dockerfile)
232-
workers = %k
233-
234-
# Number of threads per worker
235-
236-
# default value: 4 (see Dockerfile)
237-
threads = 4
238-
239-
# The right granted on the created socket
240-
chmod-socket = 666
241-
242-
# Plugin to use and interpreter config
243-
single-interpreter = true
244-
master = true
245-
plugin = python3
246-
lazy-apps = true
247-
enable-threads = 4
186+
**Step 9: Run the Server**
248187

249-
# Module to import
250-
module = searx.webapp
188+
9. Start the container with the following command:
251189

252-
# Virtualenv and python path
253-
pythonpath = /usr/local/searxng/
254-
chdir = /usr/local/searxng/searx/
255-
256-
# automatically set processes name to something meaningful
257-
auto-procname = true
258-
259-
# Disable request logging for privacy
260-
disable-logging = true
261-
log-5xx = true
262-
263-
# Set the max size of a request (request-body excluded)
264-
buffer-size = 8192
265-
266-
# No keep alive
267-
268-
# See https://github.com/searx/searx-docker/issues/24
269-
add-header = Connection: close
270-
271-
# uwsgi serves the static files
272-
static-map = /static=/usr/local/searxng/searx/static
273-
274-
# expires set to one day
275-
static-expires = /* 86400
276-
static-gzip-all = True
277-
offload-threads = 4
190+
```bash
191+
docker compose up -d
278192
```
279193

280-
</details>
194+
The searXNG will be available at http://localhost:8080 (or the port number you set earlier).
281195

282196
## 2. Alternative Setup
283197

@@ -412,6 +326,7 @@ docker exec -it open-webui curl http://host.docker.internal:8080/search?q=this+i
412326
3. Set `Web Search Engine` from dropdown menu to `searxng`
413327
4. Set `Searxng Query URL` to one of the following examples:
414328

329+
- `http://localhost:8080/search?q=<query>` (using the host and host port, suitable for Docker-based setups)
415330
- `http://searxng:8080/search?q=<query>` (using the container name and exposed port, suitable for Docker-based setups)
416331
- `http://host.docker.internal:8080/search?q=<query>` (using the `host.docker.internal` DNS name and the host port, suitable for Docker-based setups)
417332
- `http://<searxng.local>/search?q=<query>` (using a local domain name, suitable for local network access)
@@ -426,7 +341,7 @@ docker exec -it open-webui curl http://host.docker.internal:8080/search?q=this+i
426341

427342
## 5. Using Web Search in a Chat
428343

429-
To access Web Search, Click on the + next to the message input field.
344+
To access Web Search, Click the Integrations button next to the + icon.
430345

431346
Here you can toggle Web Search On/Off.
432347

3.29 KB
Loading

0 commit comments

Comments
 (0)