installation-nginx.rst 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. .. _installation nginx:
  2. ==================
  3. Install with nginx
  4. ==================
  5. .. _nginx:
  6. https://docs.nginx.com/nginx/admin-guide/
  7. .. _nginx server configuration:
  8. https://docs.nginx.com/nginx/admin-guide/web-server/web-server/#setting-up-virtual-servers
  9. .. _nginx beginners guide:
  10. http://nginx.org/en/docs/beginners_guide.html
  11. .. _Getting Started wiki:
  12. https://www.nginx.com/resources/wiki/start/
  13. .. _uWSGI support from nginx:
  14. https://uwsgi-docs.readthedocs.io/en/latest/Nginx.html
  15. .. _uwsgi_params:
  16. https://uwsgi-docs.readthedocs.io/en/latest/Nginx.html#configuring-nginx
  17. .. _SCRIPT_NAME:
  18. https://werkzeug.palletsprojects.com/en/1.0.x/wsgi/#werkzeug.wsgi.get_script_name
  19. .. contents:: Contents
  20. :depth: 2
  21. :local:
  22. :backlinks: entry
  23. The nginx HTTP server
  24. =====================
  25. If nginx_ is not installed (uwsgi will not work with the package nginx-light),
  26. install it now.
  27. .. tabs::
  28. .. group-tab:: Ubuntu / debian
  29. .. code:: sh
  30. sudo -H apt-get install nginx
  31. .. group-tab:: Arch Linux
  32. .. code-block:: sh
  33. sudo -H pacman -S nginx-mainline
  34. sudo -H systemctl enable nginx
  35. sudo -H systemctl start nginx
  36. .. group-tab:: Fedora / RHEL
  37. .. code-block:: sh
  38. sudo -H dnf install nginx
  39. sudo -H systemctl enable nginx
  40. sudo -H systemctl start nginx
  41. Now at http://localhost you should see a *Welcome to nginx!* page, on Fedora you
  42. see a *Fedora Webserver - Test Page*. The test page comes from the default
  43. `nginx server configuration`_. How this default intro site is configured,
  44. depends on the linux distribution:
  45. .. tabs::
  46. .. group-tab:: Ubuntu / debian
  47. .. code:: sh
  48. less /etc/nginx/nginx.conf
  49. there is a line including site configurations from:
  50. .. code:: nginx
  51. include /etc/nginx/sites-enabled/*;
  52. .. group-tab:: Arch Linux
  53. .. code-block:: sh
  54. less /etc/nginx/nginx.conf
  55. in there is a configuration section named ``server``:
  56. .. code-block:: nginx
  57. server {
  58. listen 80;
  59. server_name localhost;
  60. # ...
  61. }
  62. .. group-tab:: Fedora / RHEL
  63. .. code-block:: sh
  64. less /etc/nginx/nginx.conf
  65. there is a line including site configurations from:
  66. .. code:: nginx
  67. include /etc/nginx/conf.d/*.conf;
  68. .. _nginx searx site:
  69. A nginx searx site
  70. ==================
  71. .. sidebar:: public to the internet?
  72. If your searx instance is public, stop here and first install :ref:`filtron
  73. reverse proxy <filtron.sh>` and :ref:`result proxy morty <morty.sh>`, see
  74. :ref:`installation scripts`. If already done, follow setup: *searx via
  75. filtron plus morty*.
  76. Now you have to create a configuration for the searx site. If nginx_ is new to
  77. you, the `nginx beginners guide`_ is a good starting point and the `Getting
  78. Started wiki`_ is always a good resource *to keep in the pocket*.
  79. .. tabs::
  80. .. group-tab:: Ubuntu / debian
  81. Create configuration at ``/etc/nginx/sites-available/searx`` and place a
  82. symlink to sites-enabled:
  83. .. code:: sh
  84. sudo -H ln -s /etc/nginx/sites-available/searx /etc/nginx/sites-enabled/searx
  85. .. group-tab:: Arch Linux
  86. In the ``/etc/nginx/nginx.conf`` file, replace the configuration section
  87. named ``server``.
  88. .. group-tab:: Fedora / RHEL
  89. Create configuration at ``/etc/nginx/conf.d/searx`` and place a
  90. symlink to sites-enabled:
  91. .. tabs::
  92. .. group-tab:: searx via filtron plus morty
  93. Use this setup, if your instance is public to the internet, compare
  94. figure: :ref:`architecture <arch public>` and :ref:`installation scripts`.
  95. 1. Configure a reverse proxy for :ref:`filtron <filtron.sh>`, listening on
  96. *localhost 4004* (:ref:`filtron route request`):
  97. .. code:: nginx
  98. location / {
  99. proxy_pass http://127.0.0.1:4004/;
  100. proxy_set_header Host $http_host;
  101. proxy_set_header X-Real-IP $remote_addr;
  102. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  103. proxy_set_header X-Scheme $scheme;
  104. }
  105. 2. Configure reverse proxy for :ref:`morty <searx morty>`, listening on
  106. *localhost 3000*:
  107. .. code:: nginx
  108. location /morty {
  109. proxy_pass http://127.0.0.1:3000/;
  110. proxy_set_header Host $http_host;
  111. proxy_set_header X-Real-IP $remote_addr;
  112. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  113. proxy_set_header X-Scheme $scheme;
  114. }
  115. Note that reverse proxy advised to be used in case of single-user or
  116. low-traffic instances. For a fully result proxification add :ref:`morty's
  117. <searx morty>` **public URL** to your :origin:`searx/settings.yml`:
  118. .. code:: yaml
  119. result_proxy:
  120. # replace example.org with your server's public name
  121. url : https://example.org/morty
  122. server:
  123. image_proxy : True
  124. .. group-tab:: proxy or uWSGI
  125. Be warned, with this setup, your instance isn't :ref:`protected <searx
  126. filtron>`. Nevertheless it is good enough for intranet usage and it is a
  127. excellent example of; *how different services can be set up*. The next
  128. example shows a reverse proxy configuration wrapping the :ref:`searx-uWSGI
  129. application <uwsgi configuration>`, listening on ``http =
  130. 127.0.0.1:8888``.
  131. .. code:: nginx
  132. location / {
  133. proxy_pass http://127.0.0.1:8888;
  134. proxy_set_header Host $host;
  135. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  136. proxy_set_header X-Scheme $scheme;
  137. proxy_set_header X-Script-Name /searx;
  138. proxy_buffering off;
  139. }
  140. Alternatively you can use the `uWSGI support from nginx`_ via unix
  141. sockets. For socket communication, you have to activate ``socket =
  142. /run/uwsgi/app/searx/socket`` and comment out the ``http =
  143. 127.0.0.1:8888`` configuration in your :ref:`uwsgi ini file <uwsgi
  144. configuration>`.
  145. The example shows a nginx virtual ``server`` configuration, listening on
  146. port 80 (IPv4 and IPv6 http://[::]:80). The uWSGI app is configured at
  147. location ``/`` by importing the `uwsgi_params`_ and passing requests to
  148. the uWSGI socket (``uwsgi_pass``). The ``server``\'s root points to the
  149. :ref:`searx-src clone <searx-src>` and wraps directly the
  150. :origin:`searx/static/` content at ``location /static``.
  151. .. code:: nginx
  152. server {
  153. # replace example.org with your server's public name
  154. server_name example.org;
  155. listen 80;
  156. listen [::]:80;
  157. location / {
  158. include uwsgi_params;
  159. uwsgi_pass unix:/run/uwsgi/app/searx/socket;
  160. }
  161. root /usr/local/searx/searx-src/searx;
  162. location /static { }
  163. }
  164. If not already exists, create a folder for the unix sockets, which can be
  165. used by the searx account:
  166. .. code:: bash
  167. mkdir -p /run/uwsgi/app/searx/
  168. sudo -H chown -R searx:searx /run/uwsgi/app/searx/
  169. .. group-tab:: proxy at subdir URL
  170. Be warned, with these setups, your instance isn't :ref:`protected <searx
  171. filtron>`. The examples are just here to demonstrate how to export the
  172. searx application from a subdirectory URL ``https://example.org/searx/``.
  173. .. code:: nginx
  174. location /searx {
  175. proxy_pass http://127.0.0.1:8888;
  176. proxy_set_header Host $host;
  177. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  178. proxy_set_header X-Scheme $scheme;
  179. proxy_set_header X-Script-Name /searx;
  180. proxy_buffering off;
  181. }
  182. location /searx/static {
  183. alias /usr/local/searx/searx-src/searx/static;
  184. }
  185. The ``X-Script-Name /searx`` is needed by the searx implementation to
  186. calculate relative URLs correct. The next example shows a uWSGI
  187. configuration. Since there are no HTTP headers in a (u)WSGI protocol, the
  188. value is shipped via the SCRIPT_NAME_ in the WSGI environment.
  189. .. code:: nginx
  190. location /searx/static {
  191. alias /usr/local/searx/searx-src/searx;
  192. }
  193. location /searx {
  194. uwsgi_param SCRIPT_NAME /searx;
  195. include uwsgi_params;
  196. uwsgi_pass unix:/run/uwsgi/app/searx/socket;
  197. }
  198. For searx to work correctly the ``base_url`` must be set in the
  199. :origin:`searx/settings.yml`.
  200. .. code:: yaml
  201. server:
  202. # replace example.org with your server's public name
  203. base_url : https://example.org/searx/
  204. Restart service:
  205. .. tabs::
  206. .. group-tab:: Ubuntu / debian
  207. .. code:: sh
  208. sudo -H systemctl restart nginx
  209. sudo -H service uwsgi restart searx
  210. .. group-tab:: Arch Linux
  211. .. code:: sh
  212. sudo -H systemctl restart nginx
  213. sudo -H systemctl restart uwsgi@searx
  214. .. group-tab:: Fedora
  215. .. code:: sh
  216. sudo -H systemctl restart nginx
  217. sudo -H touch /etc/uwsgi.d/searx.ini
  218. Disable logs
  219. ============
  220. For better privacy you can disable nginx logs in ``/etc/nginx/nginx.conf``.
  221. .. code:: nginx
  222. http {
  223. # ...
  224. access_log /dev/null;
  225. error_log /dev/null;
  226. # ...
  227. }