The OS of my server:

Distributor ID: Ubuntu
Description:    Ubuntu 16.04.2 LTS
Release:    16.04
Codename:   xenial
Apahce version:Apache/2.4.18 (Ubuntu)

I'm so sorry that my poor English,I will try my best to describe it clearly.

I've added the cache directives to my configuration files,and enabled following modules:cache,cache_disk,expire,headers.

If the cache was fresh(The expiration time was 10 seconds in my file),chrome got response whit code 200 from local cache.But when the cache was stale,the apache server did not check whether the content is still fresh before serving stale content to client.

Chrome got code 200 again,and never got the code 304.What's wrong with my configuration?There are my configurations:

1. /etc/apache2/apache2.conf

Mutex file:${APACHE_LOCK_DIR} default
Timeout 300
ServerName smt.lhc.com
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel debug 
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

2. /etc/apache2/mods-available/cache_disk.conf

<IfModule mod_cache_disk.c>

 CacheEnable disk /

CacheDirLevels 2

CacheDirLength 1


3. /etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>

    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/smt-web
    #DocumentRoot /var/www/html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

<Directory "/var/www/smt-web">

    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} -f [OR]

    RewriteCond %{REQUEST_FILENAME} -d

    RewriteRule ^ - [L]

    RewriteRule ^ index.html [L]

 CacheQuickHandler off

CacheLock on
CacheLockPath /tmp/mod_cache-lock
CacheLockMaxAge 5

CacheIgnoreHeaders Set-Cookie

<Location />
    CacheEnable disk
    CacheHeader on

    CacheDefaultExpire 600
    CacheMaxExpire 86400
    CacheLastModifiedFactor 0.5

    ExpiresActive on
    ExpiresDefault "access plus 10 sceonds"

    Header merge Cache-Control public
    FileETag All

Your configuration looks exactly same like the Digital Ocean configuration https://www.digitalocean.com/community/tutorials/how-to-configure-apache-content-caching-on-ubuntu-14-04

You can add %{cache-status}e to the LogFormat line to log the cache status in access.log of Apache.

I am using the same configuration as above, but in my case the cache serves always the same content, don't matter what i click on the homepage.

I am afraid that config does not work for Ubuntu 16.04 and Apache 2.4.18.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.