Поднял nginx перед апачем и там все работает отлично
server {
listen 10.100.30.229:8888;
server_name api.example.com; location / {
proxy_connect_timeout 120;
proxy_send_timeout 120;
proxy_read_timeout 180;
proxy_pass http://127.0.0.1:80/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
location ~/static/image/template/[0-9]+\.png {
proxy_cache_key $scheme://$host$request_uri;
proxy_cache_methods GET HEAD;
proxy_cache awt_static_images;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
proxy_ignore_headers Cache-Control Set-Cookie Expires;
proxy_cache_valid 200 301 302 1h;
proxy_cache_bypass $http_x_nocache;
proxy_pass http://127.0.0.1:80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
add_header X-Cache-Status $upstream_cache_status;
}
}
Первое обращение
# curl -i -I http://api.example.com:8888/static/image/template/2962.png
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 27 Apr 2016 12:55:27 GMT
Content-Type: image/png
...
X-Cache-Status: MISS
Последующие обращения
# curl -i -I http://api.example.com:8888/static/image/template/2962.png
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 27 Apr 2016 12:55:30 GMT
Content-Type: image/png
...
X-Cache-Status: HIT
Спустя время заданное в proxy_cache_valid
# curl -i -I http://api.example.com:8888/static/image/template/2962.png
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 27 Apr 2016 14:16:39 GMT
Content-Type: image/png
...
X-Cache-Status: EXPIRED# curl -i -I http://api.example.com:8888/static/image/template/2962.png
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 27 Apr 2016 14:16:42 GMT
Content-Type: image/png
...
X-Cache-Status: HIT
В обход кеша
# curl -I -H "X-NOCACHE: 1" http://api.example.com:8888/static/image/template/2962.png
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 27 Apr 2016 13:19:18 GMT
Content-Type: image/png
...
X-Cache-Status: BYPASS