我启用了mod_cache和mod_disk_cache Apache模块,以便能够从PHP脚本(基于宽度和高度参数)cachingdynamic生成的图像。
一切工作正常(Apachecaching文件),只要我提供小的宽度和高度参数到我的PHP脚本。 但是,当我提供更大的参数,并且随着图像尺寸变大(大约在50k以上),Apache不再caching响应。 在这种情况下,Apache会在/ var / cache / apache / mod_disk_cache中创build一个目录,但目录是空的(它不包含.header和.data文件)。
我试图设置CacheMaxFileSize指令,但它似乎没有工作(我试图设置它在disk_cache.conf文件中的一个大的值(2000000),但它似乎没有任何效果,并在站点configuration文件中设置指令禁用所有caching – caching小文件停止工作)。
有没有人遇到类似的东西,知道如何解决它?
服务器运行Apache 2.2.22的Ubuntu 12.04
这是我的configuration:
/etc/apache2/mods-available/disk_cache.conf
<IfModule mod_disk_cache.c> # cache cleaning is done by htcacheclean, which can be configured in # /etc/default/apache2 # # For further information, see the comments in that file, # /usr/share/doc/apache2.2-common/README.Debian, and the htcacheclean(8) # man page. # This path must be the same as the one in /etc/default/apache2 CacheRoot /var/cache/apache2/mod_disk_cache # This will also cache local documents. It usually makes more sense to # put this into the configuration for just one virtual host. CacheDirLevels 2 CacheDirLength 1 CacheIgnoreCacheControl On CacheIgnoreURLSessionIdentifiers jsessionid CacheIgnoreURLSessionIdentifiers PHPSESSID CacheIgnoreHeaders Set-Cookie CacheMaxFileSize 2000000 </IfModule>
/etc/apache2/sites-available/img.mydomain.com
<VirtualHost *:80> ServerName img.mydomain.com ServerAlias img.mydomain.eu DocumentRoot /var/www/mydomain.com/img/ <Directory /> Options None AllowOverride None Order allow,deny Deny from all </Directory> <Directory /var/www/mydomain.com/> AllowOverride All </Directory> <Directory /var/www/mydomain.com/img/> Options FollowSymlinks Order allow,deny Allow from all </Directory> <IfModule mod_disk_cache.c> CacheEnable disk /cached/ </IfModule> ErrorLog ${APACHE_LOG_DIR}/img.mydomain.com-error.log LogLevel debug CustomLog ${APACHE_LOG_DIR}/img.mydomain.com-access.log combined </VirtualHost>
PHP图像生成脚本/var/www/mydomain.com/img/cached/logo.php
<?php //Generate Imagick image based on provided width and height header("Content-Type: image/" . strtolower($image->getImageFormat())); header("Content-Length: " . strlen($image)); header("Cache-Control: public, must-revalidate, max-age=2592000"); echo $image; ?>
我的一个朋友find的方法是使用wget强制整个文件的caching,简单地说:
wget http://my.domain.com/mybigfile.ogg
要么
wget -O /dev/null http://my.domain.com/mybigfile.ogg
没有 范围 !
这将迫使apachecaching整个文件。
在此之后,现在可以访问caching文件中的范围 …
(对不起,最近的答案是:我find了这个问题,所以在查看正在运行的解决方法后,我发布了这个;)