01260 734 107

High performance caching with nginx redis and php

A little how to on high performance caching using Nginx, Redis, PHP.


There are various how to's all over the internet about installing the above to your server so we won't be going into that now!.

Once all of the above is installed we need to make some configuration changes to nginx.conf and your vhost.

Firstly edit nginx.conf

$ nano /etc/nginx/nginx.conf

Inside the http{} block put the following:

  upstream redis {
    server unix:/tmp/redis.sock;

Now we need to edit the vhost file for the site you wish to cache.

$ nano /etc/nginx/sites-enabled/example.conf

Add the following inside a server{} block

location ~ \.php$ {
    set $redis_key 'cache:$scheme://$host$request_uri';
    if ($http_cookie ~* '_ndx') {
      set $redis_key '____FALSE';
    default_type   text/html;
    redis_pass redis;
    error_page 404 405 502 504 = @php;
  location @php {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass   unix:/dev/shm/example.sock;
    fastcgi_index  index.php;
    include        fastcgi_params;
    fastcgi_buffers 32 32k;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

Now test the configuration (dont restart yet)

$ /etc/init.d/nginx -t

If you have not already installed the http redis module for nginx please download and install from http://people.freebsd.org/~osa/ngx_http_redis-0.3.6.tar.gz. Recompile and restart nginx.

What we have done so far is tell Nginx to check Redis for a value with the key of cache:$scheme://$host$request_uri and if found it returns the value (the html) to the client and finishes the request trail else if not found it passes it to the @php upstream that is defined.

We now need to add things to the cache in the backend. We could do this inside Nginx directly with the redis2 module but it's not very flexible and we want the ability to make selective choices when caching to only cache certain objects for certain people, having our application do this and work out the logic at runtime is by far the most flexible and abstract way to accomplish the task.

This how to assumes you have access to the full rendered html that your application has outputted - this can be obtained using php's ob_* (output buffering) functions to collect the data into a variable.

Once you have the html string in a variable the rest is really quite simple, in lamens terms you connect to redis and add an expiring (if you wish) value with the key that was defined above (cache:$scheme://$host$request_uri). (psuedo code below)

Comments are disabled

What clients & recruiters say about us

Cannot rate the guys at Nodex enough, brilliant service from start to finish. Following the initial call with Andrew we knew the guys would look after after us and we weren’t wrong. Through every step of the process we received brilliant customer service and nothing was too much bother for them. If Heineken did web design then it would be by these guys! Already onto our next website with them. (From Trustpilot)
Big Ant Group
I had a great experience working with Nodex, they were extremely helpful from start to finish, always on hand to answer any queries or concerns. They know what they are talking about and offered some excellent advice in ways to maximise the fullest potential of my business website. The whole process was extremely efficient and the team went above and beyond in achieving my company vision. (From Trust Pilot)
Hero recruitment
Andrew and the Nodex team have been superb from the moment I asked for a demonstration on their CRM and i knew they would be the right business for me from them. Really easy to speak to, helpful and will go out of their way to provide first class customer service. Andrew has gone way beyond what I would normally expect and has helped me with tech issues outside of the actual Nodex products. Their CRM offers real value, easy to use and allows you to do far more than other options on the market and for a lower price! The connection with my company's website is also brilliant. I look forward to continuing to work with Nodex for the long term! (From Trust pilot)
Treasury search
When seeking a web designer for our new recruitment business, I initially approached a number of web design companies. Once I spoke to the team at Nodex, I knew straight away that they were the most knowledge company in their field. The service offered by the team at Nodex has been exceptional. They were on hand to offer advice, make adjustments and were very supportive from start to finish. I would recommend Nodex without any hesitation. Thank you!
Antella Recruitment
Not only was the service exemplary, the quality of my website and CRM is outstanding. Brilliant value for money. The team at Nodex have given my business their undivided attention and care during this process. I wanted a site that was easy to use and looked slick; Nodex have delivered tremendously. The Nodex CRM is easy to use, affective and concise. I am very pleased. I would recommend Nodex in a heartbeat. Fantastic work guys, thank you very much. (From Trustpilot)
Dara Recruitment
Exceptional service!! Nodex have been great throughout. The website and Recruitment CRM is absolutely amazing and has really helped us with the day to day running of clients and candidates. We would highly recommend Nodex to any recruitment agency looking for a website and/or CRM. 10 out of 10 (From Trust Pilot)
Global Vet Recruitment
Guys at Nodex are very knowledgeable, friendly and provide outstanding service. I was looking for a company to revamp our existing website, the team went through our old website and highlighted the issues that we needed to fix. They have done an excellent job in putting our new website. Would definitely recommend them to anyone looking to build a website. (From trust pilot)
Mera Peak Recruitment
Andrew, Alex and their team are highly knowledgeable and fully understand the needs of a recruitment business, which shows in the recruitment software they have developed. The CRM platform is very user friendly, has all the functionality that you would expect to see (if you don’t, they will design this for you) and is regularly updated. The set up / changeover process is swift and straight forward and the team are always there to support when needed.

I will be recommending Nodex to my network for anyone that is looking for a Recruitment Website or CRM.

(From Trust pilot)
Vet Seekers
We recently migrated to the Nodex CRM, taking up the opportunity to move to a nodex website as part of a fully integrated solution. Well...WE'RE DELIGHTED WE DID! Really pleased with the user experience, it has improved work efficiency no end, and the team love it. Extremely responsive support on any queries we raised. (Via trustpilot)
Orchard Recruitment
A fantastic fast and easy service to use, along with a very supportive team at Nodex. Its helped spend less time on admin and more on selling. This CRM makes the workflow smarter. I would recommend it to anyone.
Global Pets Recruitment


Template based recruitment website pricing

We operate a Pay Monthly solution for our recruitment platform. Pricing for this starts from £99 per month with a one off nominal setup fee of £299. This has everything you need to operate your recruitment website, including: our stellar professional website hosting, SSL certificates, daily website backups, minimal website updates and email support.

This is our preferred method of sale as it balances out the risk of a large outlay between both you and us, thus freeing cashflow to allow you to concentrate on marketing your services and growing your business.

We also offer more comprehensive monthly packages tailored to suit your needs.

Custom designed recruitment website pricing

If you would prefer a bespoke website design we can certainly accommodate your needs. Our initial build fee starts from £995. Included in your package is everything listed in the Nominal Fee Setup with the main difference being the length of your initial contract. If you would like to discuss available options please get in contact.

Each design is quoted on a client by client basis and starts with a brief, outlining your goals and requirements.

Please note that the setup fee is dependant on theme and services / functionality required for your project. Each project is quoted on an individual basis. Please get in contact to discuss your options with one of our experts today.