Welcome! Log In Create A New Profile

Advanced

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

Posted by semseoymas 
Nginx cache 1 KEY into multiple cache files (cache not running)
November 18, 2015 09:41PM
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@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@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@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@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.
Re: Nginx cache 1 KEY into multiple cache files (cache not running)
November 18, 2015 11:32PM
Some more interesting data: sometimes it HIT cache, sometimes not..... depending of referer???? I do not know how... I cannot imagine why.

(consecutive log lines filtering by uri.... I did not remove any file or cache, even not restarted nginx at all)

107.167.108.187 - - [19/Nov/2015:05:22:22 +0100] "GET /wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2014/06/Clotilde.jpg&h=50&w=50&a=c HTTP/1.1" 200 2082 "http://xxxxxx.com/2014/09/significado-del-nombre-daniela/" "Opera/9.80 (X11; Linux zvav; U; es) Presto/2.12.423 Version/12.16" Exec: "0.020" Conn: "6" Mobile: "-" Cache: MISS (0.020 sec) - Upstream: "200"
107.167.108.187 - - [19/Nov/2015:05:22:23 +0100] "GET /wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2014/06/Clotilde.jpg&h=50&w=50&a=c HTTP/1.1" 200 2082 "http://xxxxxx.com/2014/09/significado-del-nombre-daniela/" "Opera/9.80 (X11; Linux zvav; U; es) Presto/2.12.423 Version/12.16" Exec: "0.000" Conn: "4" Mobile: "-" Cache: HIT (- sec) - Upstream: "-"
107.167.108.195 - - [19/Nov/2015:05:23:11 +0100] "GET /wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2014/06/Clotilde.jpg&h=50&w=50&a=c HTTP/1.1" 200 2082 "http://xxxxxx.com/2014/09/significado-del-nombre-daniela/" "Opera/9.80 (X11; Linux zvav; U; es) Presto/2.12.423 Version/12.16" Exec: "0.037" Conn: "8" Mobile: "-" Cache: HIT (- sec) - Upstream: "-"
37.132.144.110 - - [19/Nov/2015:05:24:28 +0100] "GET /wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2014/06/Clotilde.jpg&h=50&w=50&a=c HTTP/1.1" 200 2082 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0" Exec: "0.024" Conn: "1" Mobile: "-" Cache: MISS (0.023 sec) - Upstream: "200"
37.132.144.110 - - [19/Nov/2015:05:24:31 +0100] "GET /wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2014/06/Clotilde.jpg&h=50&w=50&a=c HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0" Exec: "0.000" Conn: "2" Mobile: "-" Cache: HIT (- sec) - Upstream: "-"
107.167.108.195 - - [19/Nov/2015:05:24:45 +0100] "GET /wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2014/06/Clotilde.jpg&h=50&w=50&a=c HTTP/1.1" 200 2082 "http://xxxxxx.com/2014/09/significado-del-nombre-daniela/" "Opera/9.80 (Android; Opera Mini/11.0.1912/37.7126; U; es) Presto/2.12.423 Version/12.16" Exec: "0.038" Conn: "6" Mobile: "-" Cache: MISS (0.038 sec) - Upstream: "200"

and the files:

root@hyperserver [/var/nginx.cache/xxxx]# find -type f -exec grep -a "KEY: /wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2014/06/Clotilde.jpg&h=50&w=50&a=c" {} \;
KEY: /wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2014/06/Clotilde.jpg&h=50&w=50&a=c
KEY: /wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2014/06/Clotilde.jpg&h=50&w=50&a=c
KEY: /wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2014/06/Clotilde.jpg&h=50&w=50&a=c
root@hyperserver [/var/nginx.cache/xxxx]# find -type f -exec grep -la "KEY: /wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2014/06/Clotilde.jpg&h=50&w=50&a=c" {} \;
./7/d2/39815042547bf336bfe0c8de84e17d27
./6/73/c1463df2aaa737d2616ba5016c64f736
./2/9c/edda94a8edf68a32eb83011e918a59c2

As you see, multiple files for the same KEY (request_uri)... sometimes MISS, sometimes HIT... I cannot imagine why.

Please, could someone help me or give a clue?
Re: Nginx cache 1 KEY into multiple cache files (cache not running)
November 19, 2015 03:27AM
> proxy_cache_key $cache_uri;

Try:
proxy_cache_key $scheme$host$request_method$request_uri;

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Nginx cache 1 KEY into multiple cache files (cache not running)
November 19, 2015 08:18AM
itpp2012 Wrote:
-------------------------------------------------------
> > proxy_cache_key $cache_uri;
>
> Try:
> proxy_cache_key $scheme$host$request_method$request_uri;

Tested, but just the same:

Here, the top 10 KEYS with more cache files (clones):

root@hyperserver [/var/nginx.cache/xxxxx]# find -type f -exec grep -a "KEY: " {} \; | sort | uniq -c | sort -n | tail -n 10
114 KEY: httpxxxxx.comGET/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Domingo.jpg&h=125&w=272&a=c
116 KEY: httpxxxxx.comGET/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Alondra.jpg&h=125&w=272&a=c
117 KEY: httpxxxxx.comGET/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Alfredo.jpg&h=125&w=272&a=c
119 KEY: httpxxxxx.comGET/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2013/04/Sergio.jpg&h=50&w=50&a=c
119 KEY: httpxxxxx.comGET/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Amir.jpg&h=50&w=50&a=c
119 KEY: httpxxxxx.comGET/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Domingo.jpg&h=50&w=50&a=c
119 KEY: httpxxxxx.comGET/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Edmundo.jpg&h=50&w=50&a=c
120 KEY: httpxxxxx.comGET/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2012/11/por-que-se-producen-las-luchas-de-poder.jpg&h=50&w=50&a=c
120 KEY: httpxxxxx.comGET/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Alfredo.jpg&h=50&w=50&a=c
120 KEY: httpxxxxx.comGET/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Alondra.jpg&h=50&w=50&a=c


In other words, "KEY: httpxxxxx.comGET/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Alondra.jpg&h=50&w=50&a=c" has 120 files at cache.

I have several servers and this is the only one having this problem. I think maybe nofiles at limits.conf could be something related?

Running out of ideas... please help!
Re: Nginx cache 1 KEY into multiple cache files (cache not running)
November 19, 2015 08:43AM
semseoymas Wrote:
-------------------------------------------------------
> httpxxxxx.comGET/wp-content/themes/sahifa/timthumb.php?src=/wp-content
> /uploads/2015/11/Alondra.jpg&h=125&w=272&a=c

> httpxxxxx.comGET/wp-content/themes/sahifa/timthumb.php?src=/wp-content
> /uploads/2015/11/Alondra.jpg&h=50&w=50&a=c

Given the added values "&h=50&w=50&a=c" these entries are unique so it is working as intended.

$request_uri = $uri + $args (from memory, I haven't looked it up)
So you need to look at the documentation what each variable actually contains and either use that or strip the arguments.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Nginx cache 1 KEY into multiple cache files (cache not running)
November 19, 2015 09:02AM
Hello:

I am sorry I think you do not understood.

120 KEY: httpxxxxx.comGET/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Alondra.jpg&h=50&w=50&a=c

In other words, "KEY: httpxxxxx.comGET/wp-content/themes/sahifa/timthumb.php?src=/wp-content/uploads/2015/11/Alondra.jpg&h=50&w=50&a=c" has 120 files at cache.

So for the same exact request_uri, or your requested proxy_cache_key, there is a unique KEY. The problem here is there are 120 files using this KEY. Yes, I am including the args... if you analize my bash command line, I am grepping the line KEY and this includes the args, of course. But there are 120 files using the same args, exactly, the same KEY, exactly, the same request_uri.

If you look at logs, you see for the same KEY (same request_uri), several http request, but some are missed, some are hit!!

But 120 files for the same exact key is a bug or something is not going as it should.

Thanks so much for taking your time to review my case :)


itpp2012 Wrote:
-------------------------------------------------------
> semseoymas Wrote:
> -------------------------------------------------------
> >
> httpxxxxx.comGET/wp-content/themes/sahifa/timthumb.php?src=/wp-content
>
> > /uploads/2015/11/Alondra.jpg&h=125&w=272&a=c
>
> >
> httpxxxxx.comGET/wp-content/themes/sahifa/timthumb.php?src=/wp-content
>
> > /uploads/2015/11/Alondra.jpg&h=50&w=50&a=c
>
> Given the added values "&h=50&w=50&a=c" these entries are unique so it
> is working as intended.
>
> $request_uri = $uri + $args (from memory, I haven't looked it up)
> So you need to look at the documentation what each variable actually
> contains and either use that or strip the arguments.
Re: Nginx cache 1 KEY into multiple cache files (cache not running)
November 19, 2015 09:22AM
Ok......

It seems to be the vary header.....
https://www.maxcdn.com/blog/accept-encoding-its-vary-important/

:(

Caché is running ok, I think, although 120 files for the same KEY.
Re: Nginx cache 1 KEY into multiple cache files (cache not running)
November 19, 2015 10:09AM
Maxim said that in the other forum. You may have to manually clear the cache to see if this happens again.

---
nginx for Windows http://nginx-win.ecsds.eu/
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 115
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready