matomo-org / matomo-nginx

Nginx configuration for running Matomo
408 stars 121 forks source link

Problems caching Piwik's index.php #9

Closed hostingnuggets closed 12 years ago

hostingnuggets commented 12 years ago

Hi,

I am encountering a really weird problem. I am using nginx 1.0.10 with PHP 5.3.8 running as PHP FPM and using your config files for piwik (v1.6) with having changed the bare minimum (server_name and things like that but nothing much more).

Now the problem I get is that somehow the caching of index.php gets totally messed up: for example I logout of Piwik and login with a another user then I would see the stuff of the previous user. For me this is a real security issue. So somehow the new user which I login get the data cached from the previous user. Totally weird...

Now I noticed that if I uncomment the following two lines, as you can see below, in the "location = /index.php" in server{}:

    ## FastCGI cache.
    ## cache ui for 5m (set the same interval of your crontab)
   include sites-available/fcgi_cache.conf;
   fastcgi_cache_valid 5m;

I don't get this problem anymore. So it is pretty much related with caching... Now I still would like to be able to use caching but without this big problem.

Do you have any clues where this problem could come from? is it your config files? is it my piwik setup? or anything else?

Thanks in advance for your feedback.

celogeek commented 12 years ago

Yeah I have seen this issue, so disabling the cache for that part is good. I will try to find how to make it work by user. may be a random cookie that are the cache key, I don't know. But I have to take a look.

hostingnuggets commented 12 years ago

cheers!

celogeek commented 12 years ago

problem solve ! now cache work, and each user has it's own cache !

hostingnuggets commented 12 years ago

Nice, hope to see your commit for that one soon ;-)

celogeek commented 12 years ago

I have already commit in branch topic/new_conf :

https://github.com/perusio/piwik-nginx/commit/219406e7e6ebf2204a8894fc68a2f65d6c1a31bc

hostingnuggets commented 12 years ago

hehe thanks I didn't see that topic/new_conf branch, the name of the branch is not so explicit ;-)

hostingnuggets commented 12 years ago

Just wanted to report back: I am now running the latest commit with your cookie caching fix and until now everything looks fine. The only weird thing I see in the error.log of nginx is the following error message repeated many times:

2011/12/18 16:14:16 [crit] 21314#0: ngx_slab_alloc() failed: no memory in cache keys zone "fcgicache"

celogeek commented 12 years ago

Try to adjust the cache memory in the fastcgi cache conf. Current size key is 100k with 10m limit.

perusio commented 12 years ago

Each item takes up 128 bits, it's an MD5 hash. So 100k will give you 6400 items in cache. To make up space, the cache manager removes the items that were accessed the longest time ago, i.e., Least Recently Used. So if you want to cache more items you need to enlarge the size of the keys zone.

hostingnuggets commented 12 years ago

Ok I modified now the following cache parameters:

keys_zone=fcgicache:10m max_size=100M

and it looks like this is enough for my setup. You might consider raising a bit the default cache settings as I guess other people will encounter the same error.

perusio commented 12 years ago

Yes. We're going to iron out all the kinks on the config and we'll push a new version today. Thanks for your feedback.

hostingnuggets commented 12 years ago

Thanks to both of you too for your useful comments. Also one could lower the cache timeout setting (inactive=x) to some parameter lower than 3h instead of enlarging the cache, of course it all depends the usage of the end user. For me for example 2h is enough.

perusio commented 12 years ago

The problem with that is some times lockups may occur that take the cache manager worker away with a segfault and end up turning nginx non functional. There are some fixes for it, but you need to be running a very recent version of Nginx of the 1.1.x branch. See changelog. So increasing the inactive time is a work around. Hence the value.

hostingnuggets commented 12 years ago

Good to know! I will then keep this setting to 3h to make sure I don't run into this bug.