installation-nginx.rst 9.6 KB

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