Reverse proxy and cache server using nginx

→ Are you a new visitor? Please visit the page guidance for new visitors ←

Reverse cache server using nginx

Nginx can also be used as a cache server for serving cache static content. Doing this is also not that hard, but you need to be careful a bit of the configuration, especially about:

This is being used to read the exact hostname / subdomain / domain and requested URI for caching. It needs to have the $scheme variable in it if you use subdomain names also.

A default setting for this is:

I only included what you need to add to your virtualhost configuration that you are already using, added […] to make you understand that it means some more configuration can exist there.

  • proxy_cache_path and  proxy_temp_path — are used to set default cache folder settings and temporary folder
  • proxy_cache_key — this is important, do not forget to set this variable else content may be passed to other vhosts and that’s not good.
  • proxy_cache — you pass here the name of your cache server
  • proxy_cache_valid — set some validation on the cached files
  • proxy_cache_bypass — set the bypass headers that will invalidate the cache and refresh it

Make sure though you have created the cache folders before you reload the configuration:

And that’s about it for everything. A full configuration files for those who want only the code is bellow:

And that’s all for today, hope it helps someone and will see you again in our next article. Don’t forget to comment below and subscribe!

Cheers.

Page 1 ← Reverse cache server using nginx

Pages: 1 2

Request an article ←