apache - 强制 mediawiki squid 缓存填满所有页面

标签 apache caching mediawiki squid

为了加快 MediaWiki 站点的速度,该站点的内容使用大量模板,但在模板完成工作后几乎具有静态内容,我想设置一个 squid 服务器


https://www.mediawiki.org/wiki/Manual:PurgeList.php



https://www.mediawiki.org/wiki/Manual:Squid_caching

然后通过使用脚本执行 wget/curl 调用来“自动”填充 squid 服务器的缓存,该调用会命中 Mediawiki 的所有页面。我的预期是,在这个过程之后,每个页面都在 squid 缓存中(如果我把它做得足够大的话),然后每次访问都将由 squid 完成。

我将如何让这个工作?
例如。:

  • 如何检查我的配置?
  • 我如何知道需要多少内存?
  • 如何检查页面是否在 squid3 缓存中?

  • 到目前为止我尝试过的

    我首先了解如何使用以下方法安装 squid:
  • https://wiki.ubuntuusers.de/squid


  • https://www.mediawiki.org/wiki/Manual:Squid_caching

  • 查到我的ip地址xx.xxx.xxx.xxx(这里不公开)
    通过 ifconfig eth0

    在/etc/squid3/squid.conf 我把
    http port xx.xxx.xxx.xxx:80 transparent vhost defaultsite=XXXXXX
    cache_peer 127.0.0.1 parent 80 3130 originserver 
    
    acl manager proto cache_object
    acl localhost src 127.0.0.1/32
    
    # Allow access to the web ports
    acl web_ports port 80
    http_access allow web_ports
    
    # Allow cachemgr access from localhost only for maintenance purposes
    http_access allow manager localhost
    http_access deny manager
    
    # Allow cache purge requests from MediaWiki/localhost only
    acl purge method PURGE
    http_access allow purge localhost
    http_access deny purge
    
    # And finally deny all other access to this proxy
    http_access deny all
    

    然后我配置了我的 apache2 服务器
    # /etc/apache2/sites-enabled/000-default.conf   
    Listen 127.0.0.1:80
    

    我添加了
    $wgUseSquid = true;
    $wgSquidServers = array('xx.xxx.xxx.xxx');
    $wgSquidServersNoPurge = array('127.0.0.1');
    

    到我的 LocalSettings.php

    然后我重新启动apache2并启动squid3
    service squid3 restart
    

    并进行了第一次访问尝试
    wget --cache=off -r http://XXXXXX/mediawiki
    

    结果是:
    Resolving XXXXXXX (XXXXXXX)... xx.xxx.xxx.xxx
    Connecting to XXXXXXX (XXXXXXX|xx.xxx.xx.xxx|:80... failed: Connection refused.
    

    最佳答案

    假设 Apache 2.x。

    虽然与 Squid 无关,但您可以仅使用 Apache 模块来实现此目的。在这里查看 mod_cache:https://httpd.apache.org/docs/2.2/mod/mod_cache.html

    您可以简单地将其添加到您的 Apache 配置中,并要求 Apache 对呈现的内容进行磁盘缓存。

    您需要确保您的内容在生成的 PHP 响应中具有适当的缓存过期信息,MediaWiki 应该为您处理这个问题。

    添加这样的缓存层可能不会产生预期的结果,因为该层不知道页面是否已更改,缓存管理在这里很困难,只能用于实际的静态内容。

    Ubuntu:

    a2enmod cache cache_disk
    

    Apache 配置:
    CacheRoot /var/cache/apache2/mod_disk_cache
    CacheEnable disk /
    

    我不建议通过访问每个页面来预先填充缓存。这只会导致休眠(不常用)页面占用宝贵的空间/内存。如果您仍然希望这样做,您可以查看 wget:
    Description from: http://www.linuxjournal.com/content/downloading-entire-web-site-wget
    $ wget \
         --recursive \
         --no-clobber \
         --page-requisites \
         --html-extension \
         --convert-links \
         --restrict-file-names=windows \
         --domains website.org \
         --no-parent \
             www.website.org/tutorials/html/
    
    This command downloads the Web site www.website.org/tutorials/html/.
    
    The options are:
    
        --recursive: download the entire Web site.
    
        --domains website.org: don't follow links outside website.org.
    
        --no-parent: don't follow links outside the directory tutorials/html/.
    
        --page-requisites: get all the elements that compose the page (images, CSS and so on).
    
        --html-extension: save files with the .html extension.
    
        --convert-links: convert links so that they work locally, off-line.
    
        --restrict-file-names=windows: modify filenames so that they will work in Windows as well.
    
        --no-clobber: don't overwrite any existing files (used in case the download is interrupted and
        resumed).
    

    更好的选择:Memcached

    MediaWiki 还支持将 Memcached 用作仅用于数据和模板的非常快速的内存缓存服务。这不像 Squid 或 Apache mod_cache 这样的网站范围缓存那么残酷。 MediaWiki 将管理 Memcached,以便任何更改立即反射(reflect)在缓存存储中,这意味着您的内容将始终有效。

    请在此处查看 MediaWiki 的安装说明:https://www.mediawiki.org/wiki/Memcached

    我的建议是不要使用 Apache mod_cache 或 Squid 来执行此任务,而是安装 Memcached 并配置 MediaWiki 以使用它。

    关于apache - 强制 mediawiki squid 缓存填满所有页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33679407/

    相关文章:

    php - 如何在 htaccess 中阻止某些 url 上的 post 方法

    caching - 如何在本地缓存和使用gradle插件?

    mysql - 保留记录修订

    bash - 如何使用 mediawiki 的 api、curl 和 bash 登录?

    javascript - 在 MediaWiki 和/或 SMW 上运行页面特定 JavaScript 的最简单方法

    apache - 无法使用 Firefox 或 Chrome 浏览器访问部署在 Apache Http Server + Tomcat + SSL 架构中的应用程序

    apache - 403 用于 ServerRoot 之外的 DocumentRoot

    Java:URI 中的非法字符

    c# - 使用 OWIN 静态文件时配置客户端缓存

    hibernate - Hibernate JPA缓存