summaryrefslogtreecommitdiff
path: root/docs/admin/installation-nginx.rst
blob: 2097d7daf364ca6fe5c843fbf607745a48e5ce15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
.. _installation nginx:

==================
Install with nginx
==================

.. _nginx:
   https://docs.nginx.com/nginx/admin-guide/
.. _nginx server configuration:
   https://docs.nginx.com/nginx/admin-guide/web-server/web-server/#setting-up-virtual-servers
.. _nginx beginners guide:
   http://nginx.org/en/docs/beginners_guide.html
.. _Getting Started wiki:
   https://www.nginx.com/resources/wiki/start/
.. _uWSGI support from nginx:
   https://uwsgi-docs.readthedocs.io/en/latest/Nginx.html
.. _uwsgi_params:
   https://uwsgi-docs.readthedocs.io/en/latest/Nginx.html#configuring-nginx
.. _SCRIPT_NAME:
   https://werkzeug.palletsprojects.com/en/1.0.x/wsgi/#werkzeug.wsgi.get_script_name

.. contents:: Contents
   :depth: 2
   :local:
   :backlinks: entry


The nginx HTTP server
=====================

If nginx_ is not installed (uwsgi will not work with the package nginx-light)
install it now.


.. tabs::

   .. group-tab:: Ubuntu / debian

      .. code:: sh

         sudo -H apt-get install nginx

   .. group-tab:: Arch Linux

      .. code-block:: sh

         sudo -H pacman -S nginx-mainline
         sudo -H systemctl enable nginx
         sudo -H systemctl start nginx

   .. group-tab::  Fedora / RHEL

      .. code-block:: sh

         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`_:

.. tabs::

   .. group-tab:: Ubuntu / debian

      .. code:: sh

         less /etc/nginx/nginx.conf

      there is a line including site configurations from:

      .. code:: nginx

         include /etc/nginx/sites-enabled/*;

   .. group-tab:: Arch Linux

      .. code-block:: sh

         less /etc/nginx/nginx.conf

      in there is a configuration section named ``server``:

      .. code-block:: nginx

         server {
             listen       80;
             server_name  localhost;
             # ...
         }

   .. group-tab::  Fedora / RHEL

      .. code-block:: sh

         less /etc/nginx/nginx.conf

      there is a line including site configurations from:

      .. code:: nginx

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

.. _nginx searx site:

A nginx searx site
==================

.. sidebar:: public to the internet?

   If your searx instance is public, stop here and first install :ref:`filtron
   reverse proxy <filtron.sh>` and :ref:`result proxy morty <morty.sh>`, see
   :ref:`installation scripts`.

Now you have to create a configuration for the searx 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*.

.. tabs::

   .. group-tab:: Ubuntu / debian

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

      .. code:: sh

         sudo -H ln -s /etc/nginx/sites-available/searx /etc/nginx/sites-enabled/searx

   .. group-tab:: Arch Linux

      In the ``/etc/nginx/nginx.conf`` file, replace the configuration section
      named ``server``.

   .. group-tab::  Fedora / RHEL

      Create configuration at ``/etc/nginx/conf.d/searx`` and place a
      symlink to sites-enabled:

.. tabs::

   .. group-tab:: searx via filtron plus morty

      Use this setup, if your instance is public to the internet, compare
      figure: :ref:`architecture <arch public>`.  Configure a reverse proxy for
      :ref:`filtron <filtron.sh>`, listening on *localhost 4004* (:ref:`filtron
      route request`):

      .. code:: nginx

         location / {
             proxy_pass         http://127.0.0.1:4004/;

             proxy_set_header   Host             $http_host;
             proxy_set_header   X-Real-IP        $remote_addr;
             proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
             proxy_set_header   X-Scheme         $scheme;
         }


      Configure reverse proxy for :ref:`morty <searx morty>`, listening on
      *localhost 3000*:

      .. code:: nginx

         location /morty {
             proxy_pass         http://127.0.0.1:3000/;

             proxy_set_header   Host             $http_host;
             proxy_set_header   X-Real-IP        $remote_addr;
             proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
             proxy_set_header   X-Scheme         $scheme;
         }

      Note that reverse proxy advised to be used in case of single-user or
      low-traffic instances.  For a fully result proxification add :ref:`morty's
      <searx morty>` **public URL** to your :origin:`searx/settings.yml`:

      .. code:: yaml

         result_proxy:
             # replace example.org with your server's public name
             url : https://example.org/


   .. group-tab:: proxy or uWSGI

      Be warned, with this setup, your instance isn't :ref:`protected <searx
      filtron>`.  Nevertheless it is good enough for intranet usage and it is a
      excellent example of; *how different services can be set up*.  The next
      example shows a reverse proxy configuration wrapping the :ref:`searx-uWSGI
      application <uwsgi configuration>`, listening on ``http =
      127.0.0.1:8888``.

      .. code:: nginx

          location / {
              proxy_pass http://127.0.0.1:8888;

              proxy_set_header Host $host;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header X-Scheme $scheme;
              proxy_set_header X-Script-Name /searx;
              proxy_buffering off;
          }

      Alternatively you can use the `uWSGI support from nginx`_ via unix
      sockets.  For socket communication, you have to activate ``socket =
      /run/uwsgi/app/searx/socket`` and comment out the ``http =
      127.0.0.1:8888`` configuration in your :ref:`uwsgi ini file <uwsgi
      configuration>`.

      The example shows a nginx virtual ``server`` configuration, listening on
      port 80 (IPv4 and IPv6 http://[::]:80).  The uWSGI app is configured at
      location ``/`` by importing the `uwsgi_params`_ and passing requests to
      the uWSGI socket (``uwsgi_pass``).  The ``server``\'s root points to the
      :ref:`searx-src clone <searx-src>` and wraps directly the
      :origin:`searx/static/` content at ``location /static``.

      .. code:: nginx

         server {
             # replace example.org with your server's public name
             server_name example.org;

             listen 80;
             listen [::]:80;

             location / {
                 include uwsgi_params;
                 uwsgi_pass unix:/run/uwsgi/app/searx/socket;
             }

	     root /usr/local/searx/searx-src/searx;
             location /static { }
         }

      If not already exists, create a folder for the unix sockets, which can be
      used by the searx account:

      .. code:: bash

	 mkdir -p /run/uwsgi/app/searx/
	 sudo -H chown -R searx:searx /run/uwsgi/app/searx/

   .. group-tab:: subdirectory URL

      Be warned, with these setups, your instance isn't :ref:`protected <searx
      filtron>`.  The examples are just here to demonstrate how to export the
      searx application from a subdirectory URL ``https://example.org/searx/``.

      .. code:: nginx

          location /searx {
              proxy_pass http://127.0.0.1:8888;

              proxy_set_header Host $host;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header X-Scheme $scheme;
              proxy_set_header X-Script-Name /searx;
              proxy_buffering off;
          }

          location /searx/static {
              alias /usr/local/searx/searx-src/searx/static;
          }

      The ``X-Script-Name /searx`` is needed by the searx implementation to
      calculate relative URLs correct.  The next example shows a uWSGI
      configuration.  Since there are no HTTP headers in a (u)WSGI protocol, the
      value is shipped via the SCRIPT_NAME_ in the WSGI environment.

      .. code:: nginx

          location /searx/static {
              alias /usr/local/searx/searx-src/searx;
          }

          location /searx {
              uwsgi_param SCRIPT_NAME /searx;
              include uwsgi_params;
              uwsgi_pass unix:/run/uwsgi/app/searx/socket;
          }

      For searx to work correctly the ``base_url`` must be set in the
      :origin:`searx/settings.yml`.

      .. code:: yaml

         server:
             # replace example.org with your server's public name
             base_url : https://example.org/searx/


Restart service:

.. tabs::

   .. group-tab:: Ubuntu / debian

      .. code:: sh

         sudo -H systemctl restart nginx
         sudo -H service uwsgi restart searx

   .. group-tab:: Arch Linux

      .. code:: sh

         sudo -H systemctl restart nginx
         sudo -H systemctl restart uwsgi@searx

   .. group-tab:: Fedora

      .. code:: sh

         sudo -H systemctl restart nginx
         sudo -H touch /etc/uwsgi.d/searx.ini


Disable logs
============

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

.. code:: nginx

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