NGINX Reverse Proxy : Is it possible to proxy cache ONLY 404 (or other) html status codes

cachenginxreverse-proxy

With nginx, latest, is it possible to proxy cache ONLY specific html status code responses?

We use 410 status codes for some responses.

These are checked against our database.

When the said content is flagged as removed for ever (410), a 410 status code is sent.

This content is gone forever.

We would like to proxy cache ONLY these results.

Is this possible?

Best Answer

Use proxy_cache_valid directive, e.g.:

proxy_cache_valid 410      1m;
proxy_cache_valid any      0;

http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_valid