installation-nginx.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. # https://example.org/searx
  105. location /searx {
  106. proxy_pass http://127.0.0.1:4004/;
  107. proxy_set_header Host $http_host;
  108. proxy_set_header Connection $http_connection;
  109. proxy_set_header X-Real-IP $remote_addr;
  110. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  111. proxy_set_header X-Scheme $scheme;
  112. proxy_set_header X-Script-Name /searx;
  113. }
  114. location /searx/static {
  115. /usr/local/searx/searx-src/searx/static;
  116. }
  117. 2. Configure reverse proxy for :ref:`morty <searx morty>`, listening on
  118. *localhost 3000*:
  119. .. code:: nginx
  120. # https://example.org/morty
  121. location /morty {
  122. proxy_pass http://127.0.0.1:3000/;
  123. proxy_set_header Host $http_host;
  124. proxy_set_header Connection $http_connection;
  125. proxy_set_header X-Real-IP $remote_addr;
  126. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  127. proxy_set_header X-Scheme $scheme;
  128. }
  129. Note that reverse proxy advised to be used in case of single-user or
  130. low-traffic instances. For a fully result proxification add :ref:`morty's
  131. <searx morty>` **public URL** to your :origin:`searx/settings.yml`:
  132. .. code:: yaml
  133. result_proxy:
  134. # replace example.org with your server's public name
  135. url : https://example.org/morty
  136. server:
  137. image_proxy : True
  138. .. group-tab:: proxy or uWSGI
  139. Be warned, with this setup, your instance isn't :ref:`protected <searx
  140. filtron>`. Nevertheless it is good enough for intranet usage and it is a
  141. excellent example of; *how different services can be set up*. The next
  142. example shows a reverse proxy configuration wrapping the :ref:`searx-uWSGI
  143. application <uwsgi configuration>`, listening on ``http =
  144. 127.0.0.1:8888``.
  145. .. code:: nginx
  146. # https://hostname.local/
  147. location / {
  148. proxy_pass http://127.0.0.1:8888;
  149. proxy_set_header Host $host;
  150. proxy_set_header Connection $http_connection;
  151. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  152. proxy_set_header X-Scheme $scheme;
  153. proxy_buffering off;
  154. }
  155. Alternatively you can use the `uWSGI support from nginx`_ via unix
  156. sockets. For socket communication, you have to activate ``socket =
  157. /run/uwsgi/app/searx/socket`` and comment out the ``http =
  158. 127.0.0.1:8888`` configuration in your :ref:`uwsgi ini file <uwsgi
  159. configuration>`.
  160. The example shows a nginx virtual ``server`` configuration, listening on
  161. port 80 (IPv4 and IPv6 http://[::]:80). The uWSGI app is configured at
  162. location ``/`` by importing the `uwsgi_params`_ and passing requests to
  163. the uWSGI socket (``uwsgi_pass``). The ``server``\'s root points to the
  164. :ref:`searx-src clone <searx-src>` and wraps directly the
  165. :origin:`searx/static/` content at ``location /static``.
  166. .. code:: nginx
  167. server {
  168. # replace hostname.local with your server's name
  169. server_name hostname.local;
  170. listen 80;
  171. listen [::]:80;
  172. location / {
  173. include uwsgi_params;
  174. uwsgi_pass unix:/run/uwsgi/app/searx/socket;
  175. }
  176. root /usr/local/searx/searx-src/searx;
  177. location /static { }
  178. }
  179. If not already exists, create a folder for the unix sockets, which can be
  180. used by the searx account:
  181. .. code:: bash
  182. mkdir -p /run/uwsgi/app/searx/
  183. sudo -H chown -R searx:searx /run/uwsgi/app/searx/
  184. .. group-tab:: \.\. at subdir URL
  185. Be warned, with these setups, your instance isn't :ref:`protected <searx
  186. filtron>`. The examples are just here to demonstrate how to export the
  187. searx application from a subdirectory URL ``https://example.org/searx/``.
  188. .. code:: nginx
  189. # https://hostname.local/searx
  190. location /searx {
  191. proxy_pass http://127.0.0.1:8888;
  192. proxy_set_header Host $host;
  193. proxy_set_header Connection $http_connection;
  194. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  195. proxy_set_header X-Scheme $scheme;
  196. proxy_set_header X-Script-Name /searx;
  197. proxy_buffering off;
  198. }
  199. location /searx/static {
  200. alias /usr/local/searx/searx-src/searx/static;
  201. }
  202. The ``X-Script-Name /searx`` is needed by the searx implementation to
  203. calculate relative URLs correct. The next example shows a uWSGI
  204. configuration. Since there are no HTTP headers in a (u)WSGI protocol, the
  205. value is shipped via the SCRIPT_NAME_ in the WSGI environment.
  206. .. code:: nginx
  207. # https://hostname.local/searx
  208. location /searx {
  209. uwsgi_param SCRIPT_NAME /searx;
  210. include uwsgi_params;
  211. uwsgi_pass unix:/run/uwsgi/app/searx/socket;
  212. }
  213. location /searx/static {
  214. alias /usr/local/searx/searx-src/searx;
  215. }
  216. For searx to work correctly the ``base_url`` must be set in the
  217. :origin:`searx/settings.yml`.
  218. .. code:: yaml
  219. server:
  220. # replace example.org with your server's public name
  221. base_url : https://example.org/searx/
  222. Restart service:
  223. .. tabs::
  224. .. group-tab:: Ubuntu / debian
  225. .. code:: sh
  226. sudo -H systemctl restart nginx
  227. sudo -H service uwsgi restart searx
  228. .. group-tab:: Arch Linux
  229. .. code:: sh
  230. sudo -H systemctl restart nginx
  231. sudo -H systemctl restart uwsgi@searx
  232. .. group-tab:: Fedora
  233. .. code:: sh
  234. sudo -H systemctl restart nginx
  235. sudo -H touch /etc/uwsgi.d/searx.ini
  236. Disable logs
  237. ============
  238. For better privacy you can disable nginx logs in ``/etc/nginx/nginx.conf``.
  239. .. code:: nginx
  240. http {
  241. # ...
  242. access_log /dev/null;
  243. error_log /dev/null;
  244. # ...
  245. }