How to check if Apache caching works?

I added cache directives to my httpd.conf file, but I can’t find out how to verify that it actually caches pages and serves them. How can I check this?

I added cache directives at the server configuration level (without using VirtualHost) as:

CacheEnable disk /
CacheRoot /var/cache
CacheDefaultExpire 3600
+4
source share
7 answers

You can check if your apache really caches content or not by confirming the points below.

  • check the size of the / var / cache directory. It should grow in size after a while, when your Apache got

  • You can check the logs, there should be a response code of 302 instead of 200.

, mod_disk_cache.

+3

php. , 300 .

<?php
header("Cache-Control: must-revalidate, max-age=300");
header("Vary: Accept-Encoding");
echo time()."<br>";
?>
+1

304 , . , /var/cache/mod _proxy, , .

httpd.conf

SetEnv CACHE_MISS 1
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %{CACHE_MISS}e" combined

192.xx.xx.xx - - [29/Oct/2015:10:11:12 -0400] "GET /pathToResource/javascript/extjs/lib/extjs4/ext-all.js HTTP/1.1" 304 - "https://my-url" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36" 

,

192.xx.xx.xx - - [29/Oct/2015:10:11:12 -0400] "GET /pathToResource/javascript/extjs/lib/extjs4/ext-all.js HTTP/1.1" 304 - "https://my-url" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36" 1

1 . , F5 , , , 1.

+1

.

<IfModule mod_cache.c>
LoadModule cache_disk_module /usr/lib/apache2/modules/mod_cache_disk.so
<IfModule mod_disk_cache.c>
CacheDefaultExpire 3600
CacheEnable disk /
CacheRoot "/path/to/cache/folder/"
CacheDirLevels 2
CacheDirLength 1
</IfModule>
</IfModule>
0
CacheRoot "/var/cache/folder"

/var/log/apache2/error.log

- , , apache2 ,

mkdir -p /var/cache/folder/
chown root:www-data /var/cache/apache2/mod_cache_disk/ -R
chmod 775 /var/cache/apache2/mod_cache_disk/ -R

, , . , , - , , , 200

0

\"%{cache-status}e\" LogFormat, .

0

:

0

Source: https://habr.com/ru/post/1524135/


All Articles