installation-apache.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. .. _installation apache:
  2. ======
  3. 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. .. _apache2.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/mod/mod_so.html#loadmodule
  25. .. _IncludeOptional:
  26. https://httpd.apache.org/docs/mod/core.html#includeoptional
  27. .. _DocumentRoot:
  28. https://httpd.apache.org/docs/trunk/mod/core.html#documentroot
  29. .. _Location:
  30. https://httpd.apache.org/docs/trunk/mod/core.html#location
  31. .. _uWSGI Apache support:
  32. https://uwsgi-docs.readthedocs.io/en/latest/Apache.html
  33. .. _mod_proxy_uwsgi:
  34. https://uwsgi-docs.readthedocs.io/en/latest/Apache.html#mod-proxy-uwsgi
  35. .. _mod_proxy_http:
  36. https://httpd.apache.org/docs/current/mod/mod_proxy_http.html
  37. .. _mod_proxy:
  38. https://httpd.apache.org/docs/current/mod/mod_proxy.html
  39. This section explains how to set up a SearXNG instance using the HTTP server Apache_.
  40. If you did use the :ref:`installation scripts` and do not have any special preferences
  41. you can install the :ref:`SearXNG site <apache searxng site>` using
  42. :ref:`searxng.sh <searxng.sh overview>`:
  43. .. code:: bash
  44. $ sudo -H ./utils/searxng.sh install apache
  45. If you have special interests or problems with setting up Apache, the following
  46. section might give you some guidance.
  47. .. sidebar:: further read
  48. - `Apache Arch Linux`_
  49. - `Apache Debian`_
  50. - `apache2.README.Debian`_
  51. - `Apache Fedora`_
  52. - `Apache directives`_
  53. .. contents::
  54. :depth: 2
  55. :local:
  56. :backlinks: entry
  57. The Apache HTTP server
  58. ======================
  59. If Apache_ is not installed, install it now. If apache_ is new to you, the
  60. `Getting Started`_, `Configuration Files`_ and `Terms Used to Describe
  61. Directives`_ documentation gives first orientation. There is also a list of
  62. `Apache directives`_ *to keep in the pocket*.
  63. .. tabs::
  64. .. group-tab:: Ubuntu / debian
  65. .. code:: bash
  66. sudo -H apt-get install apache2
  67. .. group-tab:: Arch Linux
  68. .. code:: bash
  69. sudo -H pacman -S apache
  70. sudo -H systemctl enable httpd
  71. sudo -H systemctl start http
  72. .. group-tab:: Fedora / RHEL
  73. .. code:: bash
  74. sudo -H dnf install httpd
  75. sudo -H systemctl enable httpd
  76. sudo -H systemctl start httpd
  77. Now at http://localhost you should see some kind of *Welcome* or *Test* page.
  78. How this default site is configured, depends on the linux distribution
  79. (compare `Apache directives`_).
  80. .. tabs::
  81. .. group-tab:: Ubuntu / debian
  82. .. code:: bash
  83. less /etc/apache2/sites-enabled/000-default.conf
  84. In this file, there is a line setting the `DocumentRoot`_ directive:
  85. .. code:: apache
  86. DocumentRoot /var/www/html
  87. And the *welcome* page is the HTML file at ``/var/www/html/index.html``.
  88. .. group-tab:: Arch Linux
  89. .. code:: bash
  90. less /etc/httpd/conf/httpd.conf
  91. In this file, there is a line setting the `DocumentRoot`_ directive:
  92. .. code:: apache
  93. DocumentRoot "/srv/http"
  94. <Directory "/srv/http">
  95. Options Indexes FollowSymLinks
  96. AllowOverride None
  97. Require all granted
  98. </Directory>
  99. The *welcome* page of Arch Linux is a page showing the directory located
  100. at ``DocumentRoot``. This *directory* page is generated by the Module
  101. `mod_autoindex <https://httpd.apache.org/docs/2.4/mod/mod_autoindex.html>`_:
  102. .. code:: apache
  103. LoadModule autoindex_module modules/mod_autoindex.so
  104. ...
  105. Include conf/extra/httpd-autoindex.conf
  106. .. group-tab:: Fedora / RHEL
  107. .. code:: bash
  108. less /etc/httpd/conf/httpd.conf
  109. In this file, there is a line setting the ``DocumentRoot`` directive:
  110. .. code:: apache
  111. DocumentRoot "/var/www/html"
  112. ...
  113. <Directory "/var/www">
  114. AllowOverride None
  115. # Allow open access:
  116. Require all granted
  117. </Directory>
  118. On fresh installations, the ``/var/www`` is empty and the *default
  119. welcome page* is shown, the configuration is located at::
  120. less /etc/httpd/conf.d/welcome.conf
  121. .. _Debian's Apache layout:
  122. Debian's Apache layout
  123. ----------------------
  124. Be aware, Debian's Apache layout is quite different from the standard Apache
  125. configuration. For details look at the apache2.README.Debian_
  126. (``/usr/share/doc/apache2/README.Debian.gz``). Some commands you should know on
  127. Debian:
  128. * :man:`apache2ctl`: Apache HTTP server control interface
  129. * :man:`a2enmod`, :man:`a2dismod`: switch on/off modules
  130. * :man:`a2enconf`, :man:`a2disconf`: switch on/off configurations
  131. * :man:`a2ensite`, :man:`a2dissite`: switch on/off sites
  132. .. _apache modules:
  133. Apache modules
  134. --------------
  135. To load additional modules, in most distributions you have to un-comment the
  136. lines with the corresponding LoadModule_ directive, except in :ref:`Debian's
  137. Apache layout`.
  138. .. tabs::
  139. .. group-tab:: Ubuntu / debian
  140. :ref:`Debian's Apache layout` uses :man:`a2enmod` and :man:`a2dismod` to
  141. activate or disable modules:
  142. .. code:: bash
  143. sudo -H a2enmod ssl
  144. sudo -H a2enmod headers
  145. sudo -H a2enmod proxy
  146. sudo -H a2enmod proxy_http
  147. sudo -H a2enmod proxy_uwsgi
  148. .. group-tab:: Arch Linux
  149. In the ``/etc/httpd/conf/httpd.conf`` file, activate LoadModule_
  150. directives:
  151. .. code:: apache
  152. LoadModule ssl_module modules/mod_ssl.so
  153. LoadModule headers_module modules/mod_headers.so
  154. LoadModule proxy_module modules/mod_proxy.so
  155. LoadModule proxy_http_module modules/mod_proxy_http.so
  156. LoadModule proxy_uwsgi_module modules/mod_proxy_uwsgi.so
  157. .. group-tab:: Fedora / RHEL
  158. In the ``/etc/httpd/conf/httpd.conf`` file, activate LoadModule_
  159. directives:
  160. .. code:: apache
  161. LoadModule ssl_module modules/mod_ssl.so
  162. LoadModule headers_module modules/mod_headers.so
  163. LoadModule proxy_module modules/mod_proxy.so
  164. LoadModule proxy_http_module modules/mod_proxy_http.so
  165. LoadModule proxy_uwsgi_module modules/mod_proxy_uwsgi.so
  166. .. _apache sites:
  167. Apache sites
  168. ------------
  169. .. tabs::
  170. .. group-tab:: Ubuntu / debian
  171. In :ref:`Debian's Apache layout` you create a ``searxng.conf`` with the
  172. ``<Location /searxng >`` directive and save this file in the *sites
  173. available* folder at ``/etc/apache2/sites-available``. To enable the
  174. ``searxng.conf`` use :man:`a2ensite`:
  175. .. code:: bash
  176. sudo -H a2ensite searxng.conf
  177. .. group-tab:: Arch Linux
  178. In the ``/etc/httpd/conf/httpd.conf`` file add a IncludeOptional_
  179. directive:
  180. .. code:: apache
  181. IncludeOptional sites-enabled/*.conf
  182. Create two folders, one for the *available sites* and one for the *enabled sites*:
  183. .. code:: bash
  184. mkdir -p /etc/httpd/sites-available
  185. mkdir -p /etc/httpd/sites-enabled
  186. Create configuration at ``/etc/httpd/sites-available`` and place a
  187. symlink to ``sites-enabled``:
  188. .. code:: bash
  189. sudo -H ln -s /etc/httpd/sites-available/searxng.conf \
  190. /etc/httpd/sites-enabled/searxng.conf
  191. .. group-tab:: Fedora / RHEL
  192. In the ``/etc/httpd/conf/httpd.conf`` file add a IncludeOptional_
  193. directive:
  194. .. code:: apache
  195. IncludeOptional sites-enabled/*.conf
  196. Create two folders, one for the *available sites* and one for the *enabled sites*:
  197. .. code:: bash
  198. mkdir -p /etc/httpd/sites-available
  199. mkdir -p /etc/httpd/sites-enabled
  200. Create configuration at ``/etc/httpd/sites-available`` and place a
  201. symlink to ``sites-enabled``:
  202. .. code:: bash
  203. sudo -H ln -s /etc/httpd/sites-available/searxng.conf \
  204. /etc/httpd/sites-enabled/searxng.conf
  205. .. _apache searxng site:
  206. Apache's SearXNG site
  207. =====================
  208. .. _mod_uwsgi: https://uwsgi-docs.readthedocs.io/en/latest/Apache.html#mod-uwsgi
  209. .. sidebar:: uWSGI
  210. Use mod_proxy_uwsgi_ / don't use the old mod_uwsgi_ anymore.
  211. To proxy the incoming requests to the SearXNG instance Apache needs the
  212. mod_proxy_ module (:ref:`apache modules`).
  213. .. sidebar:: HTTP headers
  214. With ProxyPreserveHost_ the incoming ``Host`` header is passed to the proxied
  215. host.
  216. Depending on what your SearXNG installation is listening on, you need a http
  217. mod_proxy_http_) or socket (mod_proxy_uwsgi_) communication to upstream.
  218. The :ref:`installation scripts` installs the :ref:`reference setup
  219. <use_default_settings.yml>` and a :ref:`uwsgi setup` that listens on a socket by default.
  220. You can install and activate your own ``searxng.conf`` like shown in
  221. :ref:`apache sites`.
  222. .. tabs::
  223. .. group-tab:: socket
  224. .. kernel-include:: $DOCS_BUILD/includes/searxng.rst
  225. :start-after: START apache socket
  226. :end-before: END apache socket
  227. .. group-tab:: http
  228. .. kernel-include:: $DOCS_BUILD/includes/searxng.rst
  229. :start-after: START apache http
  230. :end-before: END apache http
  231. .. _restart apache:
  232. Restart service:
  233. .. tabs::
  234. .. group-tab:: Ubuntu / debian
  235. .. code:: bash
  236. sudo -H systemctl restart apache2
  237. sudo -H service uwsgi restart searxng
  238. .. group-tab:: Arch Linux
  239. .. code:: bash
  240. sudo -H systemctl restart httpd
  241. sudo -H systemctl restart uwsgi@searxng
  242. .. group-tab:: Fedora / RHEL
  243. .. code:: bash
  244. sudo -H systemctl restart httpd
  245. sudo -H touch /etc/uwsgi.d/searxng.ini
  246. disable logs
  247. ============
  248. For better privacy you can disable Apache logs. In the examples above activate
  249. one of the lines and `restart apache`_:
  250. .. code:: apache
  251. SetEnvIf Request_URI "/searxng" dontlog
  252. # CustomLog /dev/null combined env=dontlog
  253. The ``CustomLog`` directive disables logs for the entire (virtual) server, use it
  254. when the URL of the service does not have a path component (``/searxng``), so when
  255. SearXNG is located at root (``/``).