homme.io
Clean.Precise.Quick.
..
SAKURA
PLATO
Фотография
Философия
Искусство
История
DevOps
C/C++
DBMS
Oracle
Спорт
Linux
Rust
Lua
IT

Infinitum.Aeterna
2025.Тайланд
2025.08.Турция
2025.Зубовка
2025.Дивеево
2025.Суздаль-Плес
2025.Рязань
2024.Зубовка
2024.Египет
2024.Эмираты
2024.01.Зоопарк
2024.Китай
Иран в лицах
2023.Иран
2023.09.Египет
2023.07.Царицыно
2023.06.Москва
2023.06.Египет
2023.05.Москва
2023.Стамбул
2023.02.Царицыно
2023.01.Зубовка
2023.ЧИА
2023.ЗИМА
2022.11.Турция
2022.Аносино
2022.ОСЕНЬ
2022.08.Зубовка
2022.07.Турция
2022.Раменское
2022.ЛЕТО
2022.Архангельское
2022.Парк
2022.Петербург
2022.Ярославль
2022.03.Зубовка
2022.Кокошкино
2022.Сочи
2022.ВЕСНА
2022.02.Царицыно
2022.Стамбул
2022.02.Коломенское
2022.ЗИМА
2021.Зубовка
2021.ОСЕНЬ
2021.Египет
2021.Раменское
2021.ЛЕТО
2021.Дивеево
2021.Азов
2021.02.Зоопарк
2021.Карелия
2020.Петербург
2020.Турция
2020.Аносино
2020.Азов
2020.Верея
2020.Арктика
2020.Греция
2019.Турция
2019.Зубовка
2019.Дагестан
2019.Дагестан+
2019.Египет
2019.Италия
2019.Куликово поле
2019.Калуга
2019.02.Танцы
2019.Байкал
2018.Переславль
2018.Плес
2018.Березка
2018.Крым
2018.Азов
2018.Калининград
2018.Петербург
2018.Эльбрус
2017.Турция
2015.Египет
2013.Египет
2013.Рим
Разное

Enable caching in Nginx Reverse Proxy (and solve cache MISS only)

In a lot of setups where a reverse proxy is needed, nginx is my first choice. But nginx can do more than just making a connection to backend/upstream servers, it can also serve as caching server. This makes sense and is helpful when all upstream servers are down.
On this page I first describe how caching can be enabled and afterwards how I needed to troubleshoot "MISS only" responses from the nginx reverse proxy.

Enable Caching on Nginx

To enable caching, there are two parameters to be set: proxy_cache_path, which defines a "caching zone" and proxy_cache_key, which defines how nginx should organize its internal file hierarchy for the cache.

proxy_cache_path must be defined in the http section of nginx, therefore on Ubuntu 14.04 LTS I added the caching parameters into /etc/nginx/nginx.conf. proxy_cache_key could also be defined in server and even location sections, but in my scenario the caching only serves for one application so I decided to put both into the http section:

http {
...]
proxy_cache_path  /var/www/cache levels=1:2 keys_zone=fatcache:8m max_size=1000m inactive=600m;
proxy_cache_key "$scheme$host$request_uri";
...]

This defines "/var/www/cache" as the caching directory for the zone "fatcache". For a more detailed description, you should take a look at the official documentation of proxy_cache_path.
Take sure the directory exists and Nginx (www-data) has write permissions on it.
The proxy_cache_key setting in this example means that the cache file is created based on the http scheme, the hostname and the requested URL, for example: http://myapp.example.com/caching/my/app.

Now that nginx has the groundstone configuration for caching, we need to tell nginx, where we want to use the caching zone called fatcache. Here I decided to only cache requests to a certain URI, therefore I defined this in a location section

Source: https://www.claudiokuenzler.com/blog/582/enable-caching-nginx-reverse-proxy-troubleshoot-cache-miss-only#.XAPYYy1eOu4

sdmrnv [2.48ms]