apache 缓存不生效

hzcc123 2017-07-20 05:06:03
按照这篇文章配置了apache缓存:https://www.digitalocean.com/community/tutorials/how-to-configure-apache-content-caching-on-ubuntu-14-04
配置好apache 缓存,模块也启用了。设置缓存过期时间是10秒。缓存没过期时,可以从本地浏览器缓存访问。缓存过期后,预期是要服务器验证缓存,如果缓存可以继续使用,返回304代码,更改本地缓存过期时间,继续使用本地缓存。但我的情况是并没有验证Last-Modified和Etag,而是直接又从服务器请求资源了,从未返回304.

环境介绍:
服务器:Ubuntu 16.04.2 LTS xenial
Apache:Apache/2.4.18 (Ubuntu)
客户端:Chrome

配置文件:
**1./etc/apache2/apache2.conf**
Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
ServerName smt.lhc.com
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
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
</IfModule>

**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
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
</Directory>

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
</Location>
</VirtualHost>
...全文
178 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

19,612

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧