searx.favicons.rst 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 `/var/cache`_ for the
  70. cache of applications, so a suitable storage location of SearXNG's caches is
  71. folder ``/var/cache/searxng``.
  72. In a standard installation (compare :ref:`create searxng user`), the folder
  73. must be created and the user under which the SearXNG process is running must
  74. be given write permission to this folder.
  75. .. code:: bash
  76. $ sudo mkdir /var/cache/searxng
  77. $ sudo chown root:searxng /var/cache/searxng/
  78. $ sudo chmod g+w /var/cache/searxng/
  79. In container systems, a volume should be mounted for this folder. Check
  80. whether the process in the container has read/write access to the mounted
  81. folder.
  82. :py:obj:`cache.LIMIT_TOTAL_BYTES <.FaviconCacheConfig.LIMIT_TOTAL_BYTES>`:
  83. Maximum of bytes stored in the cache of all blobs. The limit is only reached
  84. at each maintenance interval after which the oldest BLOBs are deleted; the
  85. limit is exceeded during the maintenance period.
  86. .. attention::
  87. If the maintenance period is too long or maintenance is switched
  88. off completely, the cache grows uncontrollably.
  89. SearXNG hosters can change other parameters of the cache as required:
  90. - :py:obj:`cache.HOLD_TIME <.FaviconCacheConfig.HOLD_TIME>`
  91. - :py:obj:`cache.BLOB_MAX_BYTES <.FaviconCacheConfig.BLOB_MAX_BYTES>`
  92. Maintenance of the cache
  93. ------------------------
  94. Regular maintenance of the cache is required! By default, regular maintenance
  95. is triggered automatically as part of the client requests:
  96. - :py:obj:`cache.MAINTENANCE_MODE <.FaviconCacheConfig.MAINTENANCE_MODE>` (default ``auto``)
  97. - :py:obj:`cache.MAINTENANCE_PERIOD <.FaviconCacheConfig.MAINTENANCE_PERIOD>` (default ``6000`` / 1h)
  98. As an alternative to maintenance as part of the client request process, it is
  99. also possible to carry out maintenance using an external process. For example,
  100. by creating a :man:`crontab` entry for maintenance:
  101. .. code:: bash
  102. $ python -m searx.favicons cache maintenance
  103. The following command can be used to display the state of the cache:
  104. .. code:: bash
  105. $ python -m searx.favicons cache state
  106. .. _favicon proxy setup:
  107. Proxy configuration
  108. ===================
  109. Most of the options of the :py:obj:`Favicons-Proxy <.favicons.proxy>` are
  110. already set sensibly with settings from the :ref:`settings.yml <searxng
  111. settings.yml>` and should not normally be adjusted.
  112. .. code:: toml
  113. [favicons.proxy]
  114. max_age = 5184000 # 60 days / default: 7 days (604800 sec)
  115. :py:obj:`max_age <.FaviconProxyConfig.max_age>`:
  116. The `HTTP Cache-Control max-age`_ response directive indicates that the
  117. response remains fresh until N seconds after the response is generated. This
  118. setting therefore determines how long a favicon remains in the client's cache.
  119. As a rule, in the favicons infrastructure of SearXNG's this setting only
  120. affects favicons whose byte size exceeds :ref:`BLOB_MAX_BYTES <favicon cache
  121. setup>` (the other favicons that are already in the cache are embedded as
  122. `data URL`_ in the :py:obj:`generated HTML <.favicons.proxy.favicon_url>`,
  123. which can greatly reduce the number of additional requests).
  124. .. _register resolvers:
  125. Register resolvers
  126. ------------------
  127. A :py:obj:`resolver <.favicon.resolvers>` is a function that obtains the favicon
  128. from an external source. The resolver functions available to the user are
  129. registered with their fully qualified name (FQN_) in a ``resolver_map``.
  130. If no ``resolver_map`` is defined in the ``favicon.toml``, the favicon
  131. infrastructure of SearXNG generates this ``resolver_map`` automatically
  132. depending on the ``settings.yml``. SearXNG would automatically generate the
  133. following TOML configuration from the following YAML configuration:
  134. .. code:: yaml
  135. search:
  136. favicon_resolver: "duckduckgo"
  137. .. code:: toml
  138. [favicons.proxy.resolver_map]
  139. "duckduckgo" = "searx.favicons.resolvers.duckduckgo"
  140. If this automatism is not desired, then (and only then) a separate
  141. ``resolver_map`` must be created. For example, to give the user two resolvers to
  142. choose from, the following configuration could be used:
  143. .. code:: toml
  144. [favicons.proxy.resolver_map]
  145. "duckduckgo" = "searx.favicons.resolvers.duckduckgo"
  146. "allesedv" = "searx.favicons.resolvers.allesedv"
  147. # "google" = "searx.favicons.resolvers.google"
  148. # "yandex" = "searx.favicons.resolvers.yandex"
  149. .. note::
  150. With each resolver, the resource requirement increases significantly.
  151. The number of resolvers increases:
  152. - the number of incoming/outgoing requests and
  153. - the number of favicons to be stored in the cache.
  154. In the following we list the resolvers available in the core of SearXNG, but via
  155. the FQN_ it is also possible to implement your own resolvers and integrate them
  156. into the *proxy*:
  157. - :py:obj:`searx.favicons.resolvers.duckduckgo`
  158. - :py:obj:`searx.favicons.resolvers.allesedv`
  159. - :py:obj:`searx.favicons.resolvers.google`
  160. - :py:obj:`searx.favicons.resolvers.yandex`
  161. .. _SQLite:
  162. https://www.sqlite.org/
  163. .. _FHS:
  164. https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html
  165. .. _`/var/cache`:
  166. https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch05s05.html
  167. .. _`/tmp`:
  168. https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s18.html
  169. .. _TOML:
  170. https://toml.io/en/
  171. .. _HTTP Cache-Control max-age:
  172. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#response_directives
  173. .. _data URL:
  174. https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs
  175. .. _FQN: https://en.wikipedia.org/wiki/Fully_qualified_name