Welcome! Log In Create A New Profile

Advanced

Re: Nginx not caching the content when the response is just a plain text string

Maxim Dounin
June 22, 2017 09:38AM
Hello!

On Thu, Jun 22, 2017 at 03:51:21AM -0400, rebaca wrote:

[...]

> I am trying to access the link "localhost/cache1/sample.txt" which hits
> serverX. serverX then finds that the file is not present, takes it as MISS,
> and then forwards the request probably as
> 'localhost:8111/custom/sample.txt'. But here since "/custom/" is used as
> filter in location, my custom module handler gets invoked which simply puts
> a text string in the response body, which is then forwarded to the client. I
> am able to see the response in the html.
>
> The issue is every time I am accessing the file, this sample.txt is still
> taken, as per cache log, as a MISS (which should have been a HIT instead
> since previously 1st server serverX should have saved the text string as
> sample.txt and would have served directly)
>
> Kindly let me know why this behaviour of serverX not caching such a response
> from serverY (which is a text in the response body).

There may be multiple reasons to not cache a response even with
cache properly configured, including:

- no Cache-Control / Expires headers, and no proxy_cache_valid
configured for a particular response code;

- various headers which prevent caching, including Cache-Control
which disables caching, Expires in the past, Set-Cookie, "Vary: *";

- incomplete or incorrect response (for example, you announce
some Content-Length, but the actual body is smaller).

Some additional details can be found in the documentation, see
http://nginx.org/r/proxy_cache_valid.

If you don't see why a particular response is not cached, a
debugging log might help, see
http://nginx.org/en/docs/debugging_log.html.

--
Maxim Dounin
http://nginx.org/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Nginx not caching the content when the response is just a plain text string

rebaca June 22, 2017 03:51AM

Re: Nginx not caching the content when the response is just a plain text string

Maxim Dounin June 22, 2017 09:38AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 234
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready