Welcome! Log In Create A New Profile


proxy_cache 100% MISS

Posted by mschipperheyn 
proxy_cache 100% MISS
January 04, 2011 10:33AM

I'm trying to configure reverse proxying with caching for dynamic files. In my case through Tomcat
I'm getting 100% MISS on all requests and seeing no saves in the cache directory even though the headers seem ok for allowing storage:

e.g. header
Request URL:http://www.mysite.com/brasil/BR_pt/static/faq.html
Request Method:GET
Status Code:200 OK
Request Headers
Cookie:__gads=ID=eb6se52676eab1:T=12941f669:S=ALNI_MYspQx3HfsGuEMaO1FtX8eXDjAQ; __utmz=1.1294154668.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utma=1.1574329220.1294154668.1294154668.1294154668.1; __utmc=1; __utmb=; org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE=pt_BR
User-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10
Response Headers
Cache-Control:max-age=1800, public
Date:Tue, 04 Jan 2011 15:24:47 GMT
Expires:Tue, 04 Jan 2011 15:54:47 GMT
Set-Cookie:org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE=pt_BR; Path=/

My configuration
user www-data;
worker_processes 4;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
# multi_accept on;

http {
include /etc/nginx/mime.types;

access_log /var/log/nginx/access.log;

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=STATIC:10m
inactive=24h max_size=1g;

sendfile on;
tcp_nopush on;
#rewrite_log on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;

gzip on;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/json application/xml+rss text/javascript;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
and site config
server {
listen 80 default_server;
server_name _;
server_name_in_redirect off;
charset utf-8;
root /usr/tomcat/webapps/ROOT;
add_header Cache-Control public;

## Deny illegal Host headers
## The ~* makes it case insensitive as opposed to just a ~
if ($host !~* ^([^\.]+.mysite.com|[^\.]+.mysite.com.*)$ ) {
return 444;

## Deny certain User-Agents (case insensitive)
if ($http_user_agent ~* (Baiduspider|Jullo) ) {
return 444;

## Deny certain Referers (case insensitive)
##if ($http_referer ~* (babes|click|diamond|forsale|girl|jewelry|love|nudit|organic|poker|porn|poweroversoftware|sex|teen|video|webcam|zippo) ) {
## return 444;

## Stop Image and Document Hijacking
location ~* (\.jpg|\.png|\.css)$ {
if ($http_referer !~ ^(http://[^\.]+\.mysite.com) ) {
return 444;

## System Maintenance (Service Unavailable)
##if (-f $document_root/system_maintenance.html ) {
## error_page 503 /system_maintenance.html;
## return 503;

## All other errors get the generic error page
##error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 495 496 497 500 501 502 503 504 505 506 507 /error_page.html;
##location /error_page.html {
## internal;

location /WEB-INF/ {
deny all;
location ~ /\.ht {
deny all;
location /assets/ {
rewrite ^/assets/([^/]+)/(.*) /assets/$2;
expires 90d;
location /uploads/ {
expires 90d;
## should return 1x1 gid in case of 404
location ~* ^.+.(crossdomain\.xml|favicon\.ico|\.htm|\.txt)$ {
access_log off;
expires 30d;
location / {
keepalive_timeout 30;
try_files $uri $uri/ @proxy;
location @proxy {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_max_temp_file_size 0;
proxy_buffering off;
proxy_store off;

proxy_connect_timeout 120;
proxy_send_timeout 120;
proxy_read_timeout 120;

proxy_cache STATIC;
proxy_cache_valid 200 1d;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
proxy_cache_key "$host$request_uri";
proxy_cache_methods POST;
proxy_cache_bypass $http_pragma $http_authorization;

# All POST requests go directly
if ($request_method = POST) {
proxy_pass http://localhost:8080;
proxy_pass http://localhost:8080;


I'm wondering if the use of cookies has any effect? I have set up my site so that it is still proxy cacheable even with an active session (all session specific stuff is done through javascript) and I would want to cache files coming back according to their headers regardless of sending a session cookie.

Any suggestions are appreciated!

Re: proxy_cache 100% MISS
January 05, 2011 04:53AM
Anyone? I'm really stuck here.


Re: proxy_cache 100% MISS
January 05, 2011 08:53AM
Ok, I've found the reason why the cache is missing. Tomcat sends a cookie for logged in users.
I've built my site so that it is cacheable even if users are logged in. So, I can safely ignore those cookies.

When I set

proxy_ignore_headers Set-Cookie;

it works.
When I set

proxy_pass_header Set-Cookie;

it does NOT work. I expected it to cache the file ans strip the Set-Cookie, pass the Set-Cookie along to the end user and return it as a HIT when the next user comes along (without the Set-Cookie).

But this is ok for me. It works.


Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 54
Record Number of Users: 6 on March 20, 2015
Record Number of Guests: 148 on March 24, 2015
Powered by nginx    Powered by FreeBSD    PHP Powered    Powered by Percona     ipv6 ready