searx.favicons.rst 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. .. _favicons:
  2. ========
  3. Favicons
  4. ========
  5. .. sidebar:: warning
  6. Don't activate the favicons before reading the documentation.
  7. .. contents::
  8. :depth: 2
  9. :local:
  10. :backlinks: entry
  11. Activating the favicons in SearXNG is very easy, but this **generates a
  12. significantly higher load** in the client/server communication and increases
  13. resources needed on the server.
  14. To mitigate these disadvantages, various methods have been implemented,
  15. including a *cache*. The cache must be parameterized according to your own
  16. requirements and maintained regularly.
  17. To activate favicons in SearXNG's result list, set a default
  18. ``favicon_resolver`` in the :ref:`search <settings search>` settings:
  19. .. code:: yaml
  20. search:
  21. favicon_resolver: "duckduckgo"
  22. By default and without any extensions, SearXNG serves these resolvers:
  23. - ``duckduckgo``
  24. - ``allesedv``
  25. - ``google``
  26. - ``yandex``
  27. With the above setting favicons are displayed, the user has the option to
  28. deactivate this feature in his settings. If the user is to have the option of
  29. selecting from several *resolvers*, a further setting is required / but this
  30. setting will be discussed :ref:`later <register resolvers>` in this article,
  31. first we have to setup the favicons cache.
  32. Infrastructure
  33. ==============
  34. The infrastructure for providing the favicons essentially consists of three
  35. parts:
  36. - :py:obj:`Favicons-Proxy <.favicons.proxy>` (aka *proxy*)
  37. - :py:obj:`Favicons-Resolvers <.favicons.resolvers>` (aka *resolver*)
  38. - :py:obj:`Favicons-Cache <.favicons.cache>` (aka *cache*)
  39. To protect the privacy of users, the favicons are provided via a *proxy*. This
  40. *proxy* is automatically activated with the above activation of a *resolver*.
  41. Additional requests are required to provide the favicons: firstly, the *proxy*
  42. must process the incoming requests and secondly, the *resolver* must make
  43. outgoing requests to obtain the favicons from external sources.
  44. A *cache* has been developed to massively reduce both, incoming and outgoing
  45. requests. This *cache* is also activated automatically with the above
  46. activation of a *resolver*. In its defaults, however, the *cache* is minimal
  47. and not well suitable for a production environment!
  48. .. _favicon cache setup:
  49. Setting up the cache
  50. ====================
  51. To parameterize the *cache* and more settings of the favicons infrastructure, a
  52. TOML_ configuration is created in the file ``/etc/searxng/favicons.toml``.
  53. .. code:: toml
  54. [favicons]
  55. cfg_schema = 1 # config's schema version no.
  56. [favicons.cache]
  57. db_url = "/var/cache/searxng/faviconcache.db" # default: "/tmp/faviconcache.db"
  58. LIMIT_TOTAL_BYTES = 2147483648 # 2 GB / default: 50 MB
  59. # HOLD_TIME = 5184000 # 60 days / default: 30 days
  60. # BLOB_MAX_BYTES = 40960 # 40 KB / default 20 KB
  61. # MAINTENANCE_MODE = "off" # default: "auto"
  62. # MAINTENANCE_PERIOD = 600 # 10min / default: 1h
  63. :py:obj:`cfg_schema <.FaviconConfig.cfg_schema>`:
  64. Is required to trigger any processes required for future upgrades / don't
  65. change it.
  66. :py:obj:`cache.db_url <.FaviconCacheConfig.db_url>`:
  67. The path to the (SQLite_) database file. The default path is in the `/tmp`_
  68. folder, which is deleted on every reboot and is therefore unsuitable for a
  69. production environment. The FHS_ provides the folder for the
  70. application cache
  71. The FHS_ provides the folder `/var/cache`_ for the cache of applications, so a
  72. suitable storage location of SearXNG's caches is folder ``/var/cache/searxng``.
  73. In container systems, a volume should be mounted for this folder and in a
  74. standard installation (compare :ref:`create searxng user`), the folder must be
  75. created and the user under which the SearXNG process is running must be given
  76. write permission to this folder.
  77. .. code:: bash
  78. $ sudo mkdir /var/cache/searxng
  79. $ sudo chown root:searxng /var/cache/searxng/
  80. $ sudo chmod g+w /var/cache/searxng/
  81. :py:obj:`cache.LIMIT_TOTAL_BYTES <.FaviconCacheConfig.LIMIT_TOTAL_BYTES>`:
  82. Maximum of bytes stored in the cache of all blobs. The limit is only reached
  83. at each maintenance interval after which the oldest BLOBs are deleted; the
  84. limit is exceeded during the maintenance period.
  85. .. attention::
  86. If the maintenance period is too long or maintenance is switched
  87. off completely, the cache grows uncontrollably.
  88. SearXNG hosters can change other parameters of the cache as required:
  89. - :py:obj:`cache.HOLD_TIME <.FaviconCacheConfig.HOLD_TIME>`
  90. - :py:obj:`cache.BLOB_MAX_BYTES <.FaviconCacheConfig.BLOB_MAX_BYTES>`
  91. Maintenance of the cache
  92. ------------------------
  93. Regular maintenance of the cache is required! By default, regular maintenance
  94. is triggered automatically as part of the client requests:
  95. - :py:obj:`cache.MAINTENANCE_MODE <.FaviconCacheConfig.MAINTENANCE_MODE>` (default ``auto``)
  96. - :py:obj:`cache.MAINTENANCE_PERIOD <.FaviconCacheConfig.MAINTENANCE_PERIOD>` (default ``6000`` / 1h)
  97. As an alternative to maintenance as part of the client request process, it is
  98. also possible to carry out maintenance using an external process. For example,
  99. by creating a :man:`crontab` entry for maintenance:
  100. .. code:: bash
  101. $ python -m searx.favicons cache maintenance
  102. The following command can be used to display the state of the cache:
  103. .. code:: bash
  104. $ python -m searx.favicons cache state
  105. .. _favicon proxy setup:
  106. Proxy configuration
  107. ===================
  108. Most of the options of the :py:obj:`Favicons-Proxy <.favicons.proxy>` are
  109. already set sensibly with settings from the :ref:`settings.yml <searxng
  110. settings.yml>` and should not normally be adjusted.
  111. .. code:: toml
  112. [favicons.proxy]
  113. max_age = 5184000 # 60 days / default: 7 days (604800 sec)
  114. :py:obj:`max_age <.FaviconProxyConfig.max_age>`:
  115. The `HTTP Cache-Control max-age`_ response directive indicates that the
  116. response remains fresh until N seconds after the response is generated. This
  117. setting therefore determines how long a favicon remains in the client's cache.
  118. As a rule, in the favicons infrastructure of SearXNG's this setting only
  119. affects favicons whose byte size exceeds :ref:`BLOB_MAX_BYTES <favicon cache
  120. setup>` (the other favicons that are already in the cache are embedded as
  121. `data URL`_ in the :py:obj:`generated HTML <.favicons.proxy.favicon_url>`,
  122. which can greatly reduce the number of additional requests).
  123. .. _register resolvers:
  124. Register resolvers
  125. ------------------
  126. A :py:obj:`resolver <.favicon.resolvers>` is a function that obtains the favicon
  127. from an external source. The resolver functions available to the user are
  128. registered with their fully qualified name (FQN_) in a ``resolver_map``.
  129. If no ``resolver_map`` is defined in the ``favicon.toml``, the favicon
  130. infrastructure of SearXNG generates this ``resolver_map`` automatically
  131. depending on the ``settings.yml``. SearXNG would automatically generate the
  132. following TOML configuration from the following YAML configuration:
  133. .. code:: yaml
  134. search:
  135. favicon_resolver: "duckduckgo"
  136. .. code:: toml
  137. [favicons.proxy.resolver_map]
  138. "duckduckgo" = "searx.favicons.resolvers.duckduckgo"
  139. If this automatism is not desired, then (and only then) a separate
  140. ``resolver_map`` must be created. For example, to give the user two resolvers to
  141. choose from, the following configuration could be used:
  142. .. code:: toml
  143. [favicons.proxy.resolver_map]
  144. "duckduckgo" = "searx.favicons.resolvers.duckduckgo"
  145. "allesedv" = "searx.favicons.resolvers.allesedv"
  146. # "google" = "searx.favicons.resolvers.google"
  147. # "yandex" = "searx.favicons.resolvers.yandex"
  148. .. note::
  149. With each resolver, the resource requirement increases significantly.
  150. The number of resolvers increases:
  151. - the number of incoming/outgoing requests and
  152. - the number of favicons to be stored in the cache.
  153. In the following we list the resolvers available in the core of SearXNG, but via
  154. the FQN_ it is also possible to implement your own resolvers and integrate them
  155. into the *proxy*:
  156. - :py:obj:`searx.favicons.resolvers.duckduckgo`
  157. - :py:obj:`searx.favicons.resolvers.allesedv`
  158. - :py:obj:`searx.favicons.resolvers.google`
  159. - :py:obj:`searx.favicons.resolvers.yandex`
  160. .. _SQLite:
  161. https://www.sqlite.org/
  162. .. _FHS:
  163. https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html
  164. .. _`/var/cache`:
  165. https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch05s05.html
  166. .. _`/tmp`:
  167. https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s18.html
  168. .. _TOML:
  169. https://toml.io/en/
  170. .. _HTTP Cache-Control max-age:
  171. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#response_directives
  172. .. _data URL:
  173. https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs
  174. .. _FQN: https://en.wikipedia.org/wiki/Fully_qualified_name