PHP 5.5 FastCGI Caching

I implemented FastCGI caching on our website and saw big speed improvements. However, the FastCGI cache key does not seem unique enough. If I log in, my name will appear in the header. However, the next user to log in still sees my name in the header, assuming that the cache remains valid.

Is there a way to make the cache key unique to each user? Is it ideal to use a unique identifier from a user of cookies or a PHP session? I tried to execute the answer below, but Nginx could not restart.

Enter the value from the Set-Cookie header in nginx

Please note that my cache code is as follows:

fastcgi_cache_key "$scheme$request_method$host$request_uri";

Update: My thought is that I can parse the HTTP headers sent by Nginx, then I can capture the PHP SESSION identifier and use it. However, I cannot find an example of how to do this anywhere. Right now I have something like this that doesn't work.

http_cookie ~* PHPSESSID=([0-9a-z]+) {
    set $ses_id $1;
}
+4
source share
1 answer

I was able to solve the above problem using Nginx ngx_http_userid_module . The hardest part was actually finding the module; implementing the solution was pretty trivial.

I used their sample configuration:

userid         on;
userid_name    uid;
userid_domain  example.com;
userid_path    /;
userid_expires 365d;
userid_p3p     'policyref="/w3c/p3p.xml", CP="CUR ADM OUR NOR STA NID"';

Then the user id is added to my fastCGI cache key:

fastcgi_cache_key "$scheme$request_method$host$request_uri$uid_got";

Hope this answer helps someone find this useful module faster than me.

+4
source

Source: https://habr.com/ru/post/1536662/


All Articles