Nginx cache 1 KEY into multiple cache files (cache not running)

semseoymas nginx-forum at nginx.us
Thu Nov 19 02:40:45 UTC 2015


Hello all!

First, the specs:
nginx version: nginx/1.8.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --with-http_flv_module --with-ipv6
--with-http_mp4_module --with-pcre=/usr/local/src/publicnginx/pcre-8.35
--sbin-path=/usr/local/sbin --conf-path=/etc/nginx/nginx.conf
--pid-path=/var/run/nginx.pid --error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log --with-http_realip_module
--with-http_ssl_module --http-client-body-temp-path=/tmp/nginx_client
--http-proxy-temp-path=/tmp/nginx_proxy
--http-fastcgi-temp-path=/tmp/nginx_fastcgi --with-http_stub_status_module
--add-module=/usr/local/src/publicnginx/ngx_cache_purge --with-threads

(everything as usual, but --with-threads)

The problem here: if people asks nginx for the same request_uri, it will
create multiple files!! this way, the cache is not running ok... 

You can see with this terminal output:

root at hyperserver [/var/nginx.cache/xxxxx]# find -type f -exec grep -a "KEY:
/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Amir.jpg&h=50&w=50&a=c"
{} \;
KEY:
/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Amir.jpg&h=50&w=50&a=c
KEY:
/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Amir.jpg&h=50&w=50&a=c
KEY:
/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Amir.jpg&h=50&w=50&a=c
KEY:
/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Amir.jpg&h=50&w=50&a=c
KEY:
/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Amir.jpg&h=50&w=50&a=c

root at hyperserver [/var/nginx.cache/xxxxx]# find -type f -exec grep -la "KEY:
/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Amir.jpg&h=50&w=50&a=c"
{} \;
./7/b2/11b565d1eec91c3b1c45b95b26d8fb27
./7/f6/724563e7ef37e878a929ba2b112b8f67
./a/4d/4a55e3ebe2d00f8fe3dad638b5fbc4da
./e/1d/5cbad6ee61ad0025139302e63ae171de
./3/30/262bab653c221f922694982aef6e2303
./c/85/2163f57c0724f7b753884658ac98385c
./2/66/7c2ddb49631a53a4bdc8f599f8cc9662

root at hyperserver [/var/nginx.cache/xxxxx]# echo -n
"/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Amir.jpg&h=50&w=50&a=c"
| md5sum
2163f57c0724f7b753884658ac98385c  -

root at hyperserver [/var/nginx.cache/xxxxx]# find -type f -exec grep -la "KEY:
/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Amir.jpg&h=50&w=50&a=c"
{} \;
./7/b2/11b565d1eec91c3b1c45b95b26d8fb27
./7/f6/724563e7ef37e878a929ba2b112b8f67
./a/4d/4a55e3ebe2d00f8fe3dad638b5fbc4da
./e/1d/5cbad6ee61ad0025139302e63ae171de
./3/30/262bab653c221f922694982aef6e2303
./3/17/5869a50ae737e3985a0052634f44c173
./c/85/2163f57c0724f7b753884658ac98385c
./2/66/7c2ddb49631a53a4bdc8f599f8cc9662

As you see, for the same KEY, nginx is creating multiple files, one of them
with the common "md5sum" path/name, the rest could not understand what
calculation is done to name them....

The config is usual also:

proxy_cache_path /var/nginx.cache/xxxxx levels=1:2 keys_zone=xxxxx:3m
max_size=4G inactive=90d;

and...

          location ^~ /wp-content/themes/sahifa/timthumb.php {
                  expires 90d;
                  proxy_pass http://sharedip;
                  include proxy.inc;
                  proxy_cache xxxxx;
                  proxy_cache_key $cache_uri;
                  proxy_cache_valid 200 90d;
                  proxy_cache_use_stale error timeout updating
invalid_header http_500 http_502 http_504 http_404;
          }

my proxy server (apache) is all time proccessing the same php codes...

Somebody could give me a clue about what is happening here??? What could I
do?

Thanks.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,262943,262943#msg-262943



More information about the nginx mailing list