installation-nginx.rst 9.2 KB

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