我正在尝试配置 Apache 浏览器缓存,但它似乎有一半时间不起作用。
这是我的虚拟主机配置:
<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>
这是一个卷曲测试:
$ 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
Expires 标签仅表示未来几分钟的时间,而根据 vhost 配置,它应该是 2 周后到期。
奇怪的是,在浏览器中测试一些图像做发送时带有正确的有效期,但同一服务器虚拟主机中的其他虚拟主机却没有。mod_pagespeed 已启用,但我认为这不会改变什么?有什么想法吗?
Apache/2.4.18(Ubuntu)