installation-apache.rst 14 KB

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