我在Docker容器中使用Apache Web服务器作为缓存反向代理。版本是
Server version: Apache/2.4.10 (Debian)
Server built: Nov 28 2015 14:05:48
激活以下模块:
/usr/sbin/a2enmod proxy proxy_http
/usr/sbin/a2enmod rewrite
/usr/sbin/a2enmod cache
/usr/sbin/a2enmod cache_disk
使用在etc / apache2 / mods-enabled / cache_disk.conf中配置mod_cache
<IfModule mod_cache_disk.c>
CacheRoot /var/cache/apache2/mod_cache_disk
CacheEnable disk /
CacheDirLevels 2
CacheDirLength 1
</IfModule>
在/etc/apache2/sites-enabled/000-default.conf中,配置反向代理行为并重写URL:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
LogLevel debug rewrite:trace3
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine On
RewriteRule ^(.*)test$ http://192.168.99.100:8080$1geo [P]
ProxyPass / http://192.168.99.100:8080/
ProxyPassReverse / http://192.168.99.100:8080/
</VirtualHost>
我的目标是缓存重写的网址。在这种情况下,/ samplecache / test应该与/ samplecache / geo一样处理,并且只缓存一次,因为响应是相同的。但似乎mod_cache总是接受请求URL而不是重写的URL,即调用
curl -v http://192.168.99.100:8090/samplecache/test
curl -v http://192.168.99.100:8090/samplecache/geo
从后端传递相同的结果,但它们被缓存两次。我可以在error.log中看到/ sample / test作为缓存键而不是重写/ samplecache / geo:
[Sun May 01 16:17:05.351716 2016] [cache:debug] [pid 9:tid 139956735403776] mod_cache.c(1332): [client 192.168.99.1:52687] AH00769: cache: Caching url: /samplecache/test
[Sun May 01 16:17:05.352121 2016] [cache_disk:debug] [pid 9:tid 139956735403776] mod_cache_disk.c(1350): [client 192.168.99.1:52687] AH00737: commit_entity: Headers and body for URL http://192.168.99.100:8090/samplecache/test? cached.
如何使用重写的URL作为缓存键,以便只缓存一次。