how can I cache upstream by mime type in nginx

Francis Daly francis at daoine.org
Tue Nov 1 22:07:37 UTC 2022


On Wed, Nov 02, 2022 at 12:29:49AM +0800, Drweb Mike wrote:

Hi there,

> My front end is nginx using reverse proxy work with my backend, I was
> trying to cache images files only, but it seems doesn't work at all, the
> *$no_cache* always output default value "proxy", which should be "0" when I
> visit image files

$upstream_http_content_type is the Content-Type response header from the
upstream server, after nginx has sent a request to the upstream server.

Before nginx has sent a request to the upstream server, the variable
has no value.

If you want to use variables to decide whether nginx should handle a
request by looking in the cache before asking upstream, you should only
use variables that are available in the request, not ones that come
from upstream.

(Maybe you can use part of the request uri -- starts with /images/ or
ends with .jpg or .png, for example? It depends on what requests your
clients will be making.)

> why *$upstream_http_content_type* map doesn't works as expected

Your expectation is wrong.

Cheers,

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list