I am trying to configure Apache browser caching, but it doesn't seem to be working half the time.
This is my vhost config:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/example
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/example>
<IfModule mod_expires.c>
<FilesMatch ".+\.(jpe?g|png|gif|js|css|woff|woff2|svg|eot|ttf)$">
ExpiresActive On
ExpiresDefault "access plus 2 weeks"
</FilesMatch>
</IfModule>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
RewriteEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
Here's a curl test:
$ date -u
Fri 11 Aug 2017 00:00:47 UTC
$ curl -s -v -o /dev/null https://example.com/logo.png
* Trying 34.227.118.252...
* TCP_NODELAY set
* Connected to example.com (34.227.118.252) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: example.com
* Server certificate: Let's Encrypt Authority X3
* Server certificate: DST Root CA X3
> GET /logo.png HTTP/1.1
> Host: example.com
> User-Agent: curl/7.51.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Fri, 11 Aug 2017 00:02:06 GMT
< Server: Apache/2.4.18 (Ubuntu)
< Content-Length: 2527
< Accept-Ranges: bytes
< X-Original-Content-Length: 2696
< Etag: W/"PSA-aj-_N7_D464wY"
< Expires: Fri, 11 Aug 2017 00:06:01 GMT # <---- ??
< Cache-Control: max-age=234
< X-Content-Type-Options: nosniff
< Content-Type: image/png
<
{ [2527 bytes data]
* Curl_http_done: called premature == 0
* Connection #0 to host example.com left intact
The Expires tag is just a few minutes into the future, whereas it should be a 2 week expiry according to the vhost configuration.
Weirdly, testing in a browser, some images do get sent with the correct expiry, but others in the same server vhost don't. mod_pagespeed is enabled, but I don't think this should change things? Any ideas?
Apache/2.4.18 (Ubuntu)