installation-apache.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. .. _installation apache:
  2. ===================
  3. Install with apache
  4. ===================
  5. .. _Apache: https://httpd.apache.org/
  6. .. _Apache Debian:
  7. https://cwiki.apache.org/confluence/display/HTTPD/DistrosDefaultLayout#DistrosDefaultLayout-Debian,Ubuntu(Apachehttpd2.x):
  8. .. _README.Debian:
  9. https://salsa.debian.org/apache-team/apache2/raw/master/debian/apache2.README.Debian
  10. .. _Apache Arch Linux:
  11. https://wiki.archlinux.org/index.php/Apache_HTTP_Server
  12. .. _Apache Fedora:
  13. https://docs.fedoraproject.org/en-US/quick-docs/getting-started-with-apache-http-server/index.html
  14. .. _Apache directives:
  15. https://httpd.apache.org/docs/trunk/mod/directives.html
  16. .. _Getting Started:
  17. https://httpd.apache.org/docs/current/en/getting-started.html
  18. .. _Terms Used to Describe Directives:
  19. https://httpd.apache.org/docs/current/en/mod/directive-dict.html
  20. .. _Configuration Files:
  21. https://httpd.apache.org/docs/current/en/configuring.html
  22. .. _ProxyPreserveHost: https://httpd.apache.org/docs/trunk/mod/mod_proxy.html#proxypreservehost
  23. .. _LoadModule:
  24. https://httpd.apache.org/docs/2.4/mod/mod_so.html#loadmodule
  25. .. _DocumentRoot:
  26. https://httpd.apache.org/docs/trunk/mod/core.html#documentroot
  27. .. _Location:
  28. https://httpd.apache.org/docs/trunk/mod/core.html#location
  29. .. _uWSGI Apache support:
  30. https://uwsgi-docs.readthedocs.io/en/latest/Apache.html
  31. .. _apache uwsgi:
  32. https://uwsgi-docs.readthedocs.io/en/latest/Apache.html#mod-proxy-uwsgi
  33. .. _mod_proxy_uwsgi:
  34. https://uwsgi-docs.readthedocs.io/en/latest/Apache.html#mod-proxy-uwsgi
  35. .. sidebar:: further read
  36. - `Apache Arch Linux`_
  37. - `Apache Debian`_ and `README.Debian`_
  38. - `Apache Fedora`_
  39. - `Apache directives`_
  40. .. contents:: Contents
  41. :depth: 2
  42. :local:
  43. :backlinks: entry
  44. The apache HTTP server
  45. ======================
  46. If Apache_ is not installed, install it now. If apache_ is new to you, the
  47. `Getting Started`_, `Configuration Files`_ and `Terms Used to Describe
  48. Directives`_ documentation gives first orientation. There is also a list of
  49. `Apache directives`_ *to keep in the pocket*.
  50. .. tabs::
  51. .. group-tab:: Ubuntu / debian
  52. .. code:: sh
  53. sudo -H apt-get install apache2
  54. .. group-tab:: Arch Linux
  55. .. code:: sh
  56. sudo -H pacman -S apache
  57. sudo -H systemctl enable httpd
  58. sudo -H systemctl start http
  59. .. group-tab:: Fedora / RHEL
  60. .. code:: sh
  61. sudo -H dnf install httpd
  62. sudo -H systemctl enable httpd
  63. sudo -H systemctl start httpd
  64. Now at http://localhost you should see any kind of *Welcome* or *Test* page.
  65. How this default intro site is configured, depends on the linux distribution
  66. (compare `Apache directives`_).
  67. .. tabs::
  68. .. group-tab:: Ubuntu / debian
  69. .. code:: sh
  70. less /etc/apache2/sites-enabled/000-default.conf
  71. In this file, there is a line setting the `DocumentRoot`_ directive:
  72. .. code:: apache
  73. DocumentRoot /var/www/html
  74. And the *welcome* page is the HTML file at ``/var/www/html/index.html``.
  75. .. group-tab:: Arch Linux
  76. .. code:: sh
  77. less /etc/httpd/conf/httpd.conf
  78. In this file, there is a line setting the `DocumentRoot`_ directive:
  79. .. code:: apache
  80. DocumentRoot "/srv/http"
  81. <Directory "/srv/http">
  82. Options Indexes FollowSymLinks
  83. AllowOverride None
  84. Require all granted
  85. </Directory>
  86. The *welcome* page of Arch Linux is a page showing directory located at
  87. ``DocumentRoot``. This is *directory* page is generated by the Module
  88. `mod_autoindex <https://httpd.apache.org/docs/2.4/mod/mod_autoindex.html>`_:
  89. .. code:: apache
  90. LoadModule autoindex_module modules/mod_autoindex.so
  91. ...
  92. Include conf/extra/httpd-autoindex.conf
  93. .. group-tab:: Fedora / RHEL
  94. .. code:: sh
  95. less /etc/httpd/conf/httpd.conf
  96. In this file, there is a line setting the ``DocumentRoot`` directive:
  97. .. code:: apache
  98. DocumentRoot "/var/www/html"
  99. ...
  100. <Directory "/var/www">
  101. AllowOverride None
  102. # Allow open access:
  103. Require all granted
  104. </Directory>
  105. On fresh installations, the ``/var/www`` is empty and the *default
  106. welcome page* is shown, the configuration is located at::
  107. less /etc/httpd/conf.d/welcome.conf
  108. .. _The Debian Layout:
  109. The Debian Layout
  110. =================
  111. Be aware that the Debian layout is quite different from the standard Apache
  112. configuration. For details look at the README.Debian_
  113. (``/usr/share/doc/apache2/README.Debian.gz``). Some commands you should know on
  114. Debian:
  115. * :man:`apache2ctl`: Apache HTTP server control interface
  116. * :man:`a2enmod`, :man:`a2dismod`: switch on/off modules
  117. * :man:`a2enconf`, :man:`a2disconf`: switch on/off configurations
  118. * :man:`a2ensite`, :man:`a2dissite`: switch on/off sites
  119. .. _apache searx site:
  120. Apache Reverse Proxy
  121. ====================
  122. .. sidebar:: public to the internet?
  123. If your searx instance is public, stop here and first install :ref:`filtron
  124. reverse proxy <filtron.sh>` and :ref:`result proxy morty <morty.sh>`, see
  125. :ref:`installation scripts`. If already done, follow setup: *searx via
  126. filtron plus morty*.
  127. To setup a Apache revers proxy you have to enable the *headers* and *proxy*
  128. modules and create a `Location`_ configuration for the searx site. In most
  129. distributions you have to uncomment the lines in the main configuration file,
  130. except in the :ref:`The Debian Layout`.
  131. .. tabs::
  132. .. group-tab:: Ubuntu / debian
  133. In the Apache setup, enable headers and proxy modules:
  134. .. code:: sh
  135. sudo -H a2enmod headers
  136. sudo -H a2enmod proxy
  137. sudo -H a2enmod proxy_http
  138. In :ref:`The Debian Layout` you create a ``searx.conf`` with the
  139. ``<Location /searx >`` directive and save this file in the *sites
  140. available* folder at ``/etc/apache2/sites-available``. To enable the
  141. ``searx.conf`` use :man:`a2ensite`:
  142. .. code:: sh
  143. sudo -H a2ensite searx.conf
  144. .. group-tab:: Arch Linux
  145. In the ``/etc/httpd/conf/httpd.conf`` file, activate headers and proxy
  146. modules (LoadModule_):
  147. .. code:: apache
  148. LoadModule headers_module modules/mod_headers.so
  149. LoadModule proxy_module modules/mod_proxy.so
  150. LoadModule proxy_http_module modules/mod_proxy_http.so
  151. .. group-tab:: Fedora / RHEL
  152. In the ``/etc/httpd/conf/httpd.conf`` file, activate headers and proxy
  153. modules (LoadModule_):
  154. .. code:: apache
  155. LoadModule headers_module modules/mod_headers.so
  156. LoadModule proxy_module modules/mod_proxy.so
  157. LoadModule proxy_http_module modules/mod_proxy_http.so
  158. .. tabs::
  159. .. group-tab:: searx via filtron plus morty
  160. Use this setup, if your instance is public to the internet, compare
  161. figure: :ref:`architecture <arch public>` and :ref:`installation scripts`.
  162. 1. Configure a reverse proxy for :ref:`filtron <filtron.sh>`, listening on
  163. *localhost 4004* (:ref:`filtron route request`):
  164. .. code:: apache
  165. <Location /searx >
  166. # SetEnvIf Request_URI "/searx" dontlog
  167. # CustomLog /dev/null combined env=dontlog
  168. Require all granted
  169. Order deny,allow
  170. Deny from all
  171. #Allow from fd00::/8 192.168.0.0/16 fe80::/10 127.0.0.0/8 ::1
  172. Allow from all
  173. ProxyPreserveHost On
  174. ProxyPass http://127.0.0.1:4004
  175. RequestHeader set X-Script-Name /searx
  176. </Location>
  177. 2. Configure reverse proxy for :ref:`morty <searx morty>`, listening on
  178. *localhost 3000* (FYI: ``ProxyPreserveHost On`` is already set, see
  179. above):
  180. .. code:: apache
  181. ProxyPreserveHost On
  182. <Location /morty >
  183. # SetEnvIf Request_URI "/morty" dontlog
  184. # CustomLog /dev/null combined env=dontlog
  185. Require all granted
  186. Order deny,allow
  187. Deny from all
  188. #Allow from fd00::/8 192.168.0.0/16 fe80::/10 127.0.0.0/8 ::1
  189. Allow from all
  190. ProxyPass http://127.0.0.1:3000
  191. RequestHeader set X-Script-Name /morty
  192. </Location>
  193. Note that reverse proxy advised to be used in case of single-user or
  194. low-traffic instances. For a fully result proxification add :ref:`morty's
  195. <searx morty>` **public URL** to your :origin:`searx/settings.yml`:
  196. .. code:: yaml
  197. result_proxy:
  198. # replace example.org with your server's public name
  199. url : https://example.org/morty
  200. server:
  201. image_proxy : True
  202. uWSGI support
  203. =============
  204. Be warned, with this setup, your instance isn't :ref:`protected <searx
  205. filtron>`. Nevertheless it is good enough for intranet usage and it
  206. demonstrates: *how different the uwsgi support is, depending on the
  207. distribution*. To enable :ref:`uWSGI <searx uwsgi>` support you need to install
  208. the apache `apache uwsgi`_ support:
  209. .. tabs::
  210. .. group-tab:: Ubuntu / debian
  211. .. code:: sh
  212. sudo -H apt-get install libapache2-mod-uwsgi
  213. sudo -H a2enmod uwsgi
  214. .. group-tab:: Arch Linux
  215. .. code:: sh
  216. sudo -H pacman -S uwsgi
  217. In the ``/etc/httpd/conf/httpd.conf`` file, activate headers and proxy
  218. modules (LoadModule_):
  219. .. code:: apache
  220. LoadModule proxy_module modules/mod_proxy.so
  221. LoadModule proxy_uwsgi_module modules/mod_proxy_uwsgi.so
  222. .. group-tab:: Fedora / RHEL
  223. .. code:: sh
  224. sudo -H dnf install uwsgi
  225. FIXME: enable uwsgi in apache
  226. The next example shows a configuration using the `uWSGI Apache support`_ via
  227. unix sockets. For socket communication, you have to activate ``socket =
  228. /run/uwsgi/app/searx/socket`` and comment out the ``http = 127.0.0.1:8888``
  229. configuration in your :ref:`uwsgi ini file <uwsgi configuration>`.
  230. If not already exists, create a folder for the unix sockets, which can be
  231. used by the searx account:
  232. .. code:: bash
  233. sudo -H mkdir -p /run/uwsgi/app/searx/
  234. sudo -H chown -R searx:searx /run/uwsgi/app/searx/
  235. To limit acces to your intranet replace ``Allow from all`` directive and replace
  236. ``192.168.0.0/16`` with your subnet IP/class.
  237. .. tabs::
  238. .. group-tab:: Ubuntu / debian
  239. Debian uses the (old) `mod_uwsgi
  240. <https://uwsgi-docs.readthedocs.io/en/latest/Apache.html#mod-uwsgi>`_.
  241. .. code:: apache
  242. <IfModule mod_uwsgi.c>
  243. # SetEnvIf Request_URI "/searx" dontlog
  244. # CustomLog /dev/null combined env=dontlog
  245. <Location /searx >
  246. Require all granted
  247. Options FollowSymLinks Indexes
  248. SetHandler uwsgi-handler
  249. uWSGISocket /run/uwsgi/app/searx/socket
  250. Order deny,allow
  251. Deny from all
  252. # Allow from fd00::/8 192.168.0.0/16 fe80::/10 127.0.0.0/8 ::1
  253. Allow from all
  254. </Location>
  255. </IfModule>
  256. .. group-tab:: Arch Linux
  257. Arch Linux uses the (recommend) `mod_proxy_uwsgi`_.
  258. .. code:: apache
  259. <IfModule proxy_uwsgi_module>
  260. # SetEnvIf Request_URI /searx dontlog
  261. # CustomLog /dev/null combined env=dontlog
  262. <Location /searx>
  263. Require all granted
  264. Order deny,allow
  265. Deny from all
  266. # Allow from fd00::/8 192.168.0.0/16 fe80::/10 127.0.0.0/8 ::1
  267. Allow from all
  268. ProxyPreserveHost On
  269. ProxyPass unix:/run/uwsgi/app/searx/socket|uwsgi://uwsgi-uds-searx/
  270. </Location>
  271. </IfModule>
  272. .. group-tab:: Fedora / RHEL
  273. RHEL uses the (recommend) `mod_proxy_uwsgi`_.
  274. .. code:: apache
  275. <IfModule proxy_uwsgi_module>
  276. # SetEnvIf Request_URI /searx dontlog
  277. # CustomLog /dev/null combined env=dontlog
  278. <Location /searx>
  279. Require all granted
  280. Order deny,allow
  281. Deny from all
  282. # Allow from fd00::/8 192.168.0.0/16 fe80::/10 127.0.0.0/8 ::1
  283. Allow from all
  284. ProxyPreserveHost On
  285. ProxyPass unix:/run/uwsgi/app/searx/socket|uwsgi://uwsgi-uds-searx/
  286. </Location>
  287. </IfModule>
  288. .. _restart apache:
  289. Restart service
  290. ===============
  291. .. tabs::
  292. .. group-tab:: Ubuntu / debian
  293. .. code:: sh
  294. sudo -H systemctl restart apache2
  295. sudo -H service uwsgi restart searx
  296. .. group-tab:: Arch Linux
  297. .. code:: sh
  298. sudo -H systemctl restart httpd
  299. sudo -H systemctl restart uwsgi@searx
  300. .. group-tab:: Fedora / RHEL
  301. .. code:: sh
  302. sudo -H systemctl restart httpd
  303. sudo -H touch /etc/uwsgi.d/searx.ini
  304. disable logs
  305. ============
  306. For better privacy you can disable Apache logs. In the examples above activate
  307. one of the lines and `restart apache`_::
  308. # SetEnvIf Request_URI "/searx" dontlog
  309. # CustomLog /dev/null combined env=dontlog
  310. The ``CustomLog`` directive disable logs for the whole (virtual) server, use it
  311. when the URL of the service does not have a path component (``/searx``) / is
  312. located at root (``/``).