installation-nginx.rst 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. .. _installation nginx:
  2. =====
  3. 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. https://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. This section explains how to set up a SearXNG instance using the HTTP server nginx_.
  20. If you have used the :ref:`installation scripts` and do not have any special preferences
  21. you can install the :ref:`SearXNG site <nginx searxng site>` using
  22. :ref:`searxng.sh <searxng.sh overview>`:
  23. .. code:: bash
  24. $ sudo -H ./utils/searxng.sh install nginx
  25. If you have special interests or problems with setting up nginx, the following
  26. section might give you some guidance.
  27. .. sidebar:: further reading
  28. - nginx_
  29. - `nginx beginners guide`_
  30. - `nginx server configuration`_
  31. - `Getting Started wiki`_
  32. - `uWSGI support from nginx`_
  33. .. contents::
  34. :depth: 2
  35. :local:
  36. :backlinks: entry
  37. The nginx HTTP server
  38. =====================
  39. If nginx_ is not installed, install it now.
  40. .. tabs::
  41. .. group-tab:: Ubuntu / debian
  42. .. code:: bash
  43. sudo -H apt-get install nginx
  44. .. group-tab:: Arch Linux
  45. .. code-block:: sh
  46. sudo -H pacman -S nginx-mainline
  47. sudo -H systemctl enable nginx
  48. sudo -H systemctl start nginx
  49. .. group-tab:: Fedora / RHEL
  50. .. code-block:: sh
  51. sudo -H dnf install nginx
  52. sudo -H systemctl enable nginx
  53. sudo -H systemctl start nginx
  54. Now at http://localhost you should see a *Welcome to nginx!* page, on Fedora you
  55. see a *Fedora Webserver - Test Page*. The test page comes from the default
  56. `nginx server configuration`_. How this default site is configured,
  57. depends on the linux distribution:
  58. .. tabs::
  59. .. group-tab:: Ubuntu / debian
  60. .. code:: bash
  61. less /etc/nginx/nginx.conf
  62. There is one line that includes site configurations from:
  63. .. code:: nginx
  64. include /etc/nginx/sites-enabled/*;
  65. .. group-tab:: Arch Linux
  66. .. code-block:: sh
  67. less /etc/nginx/nginx.conf
  68. There is a configuration section named ``server``:
  69. .. code-block:: nginx
  70. server {
  71. listen 80;
  72. server_name localhost;
  73. # ...
  74. }
  75. .. group-tab:: Fedora / RHEL
  76. .. code-block:: sh
  77. less /etc/nginx/nginx.conf
  78. There is one line that includes site configurations from:
  79. .. code:: nginx
  80. include /etc/nginx/conf.d/*.conf;
  81. .. _nginx searxng site:
  82. NGINX's SearXNG site
  83. ====================
  84. Now you have to create a configuration file (``searxng.conf``) for the SearXNG
  85. site. If nginx_ is new to you, the `nginx beginners guide`_ is a good starting
  86. point and the `Getting Started wiki`_ is always a good resource *to keep in the
  87. pocket*.
  88. Depending on what your SearXNG installation is listening on, you need a http or socket
  89. communication to upstream.
  90. .. tabs::
  91. .. group-tab:: socket
  92. .. kernel-include:: $DOCS_BUILD/includes/searxng.rst
  93. :start-after: START nginx socket
  94. :end-before: END nginx socket
  95. .. group-tab:: http
  96. .. kernel-include:: $DOCS_BUILD/includes/searxng.rst
  97. :start-after: START nginx http
  98. :end-before: END nginx http
  99. The :ref:`installation scripts` installs the :ref:`reference setup
  100. <use_default_settings.yml>` and a :ref:`uwsgi setup` that listens on a socket by default.
  101. .. tabs::
  102. .. group-tab:: Ubuntu / debian
  103. Create configuration at ``/etc/nginx/sites-available/`` and place a
  104. symlink to ``sites-enabled``:
  105. .. code:: bash
  106. sudo -H ln -s /etc/nginx/sites-available/searxng.conf \
  107. /etc/nginx/sites-enabled/searxng.conf
  108. .. group-tab:: Arch Linux
  109. In the ``/etc/nginx/nginx.conf`` file, in the ``server`` section add a
  110. `include <https://nginx.org/en/docs/ngx_core_module.html#include>`_
  111. directive:
  112. .. code:: nginx
  113. server {
  114. # ...
  115. include /etc/nginx/default.d/*.conf;
  116. # ...
  117. }
  118. Create two folders, one for the *available sites* and one for the *enabled sites*:
  119. .. code:: bash
  120. mkdir -p /etc/nginx/default.d
  121. mkdir -p /etc/nginx/default.apps-available
  122. Create configuration at ``/etc/nginx/default.apps-available`` and place a
  123. symlink to ``default.d``:
  124. .. code:: bash
  125. sudo -H ln -s /etc/nginx/default.apps-available/searxng.conf \
  126. /etc/nginx/default.d/searxng.conf
  127. .. group-tab:: Fedora / RHEL
  128. Create a folder for the *available sites*:
  129. .. code:: bash
  130. mkdir -p /etc/nginx/default.apps-available
  131. Create configuration at ``/etc/nginx/default.apps-available`` and place a
  132. symlink to ``conf.d``:
  133. .. code:: bash
  134. sudo -H ln -s /etc/nginx/default.apps-available/searxng.conf \
  135. /etc/nginx/conf.d/searxng.conf
  136. Restart services:
  137. .. tabs::
  138. .. group-tab:: Ubuntu / debian
  139. .. code:: bash
  140. sudo -H systemctl restart nginx
  141. sudo -H service uwsgi restart searxng
  142. .. group-tab:: Arch Linux
  143. .. code:: bash
  144. sudo -H systemctl restart nginx
  145. sudo -H systemctl restart uwsgi@searxng
  146. .. group-tab:: Fedora / RHEL
  147. .. code:: bash
  148. sudo -H systemctl restart nginx
  149. sudo -H touch /etc/uwsgi.d/searxng.ini
  150. Disable logs
  151. ============
  152. For better privacy you can disable nginx logs in ``/etc/nginx/nginx.conf``.
  153. .. code:: nginx
  154. http {
  155. # ...
  156. access_log /dev/null;
  157. error_log /dev/null;
  158. # ...
  159. }