Welcome! Log In Create A New Profile

Advanced

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

June 22, 2017 03:51AM
SUMMARY:
Nginx not caching the content when the response is just a plain text string

DETAILS:
Below shows the connection between entities:
[ client ] <---> [ serverX ] <---> [ serverY ]

serverX and serverY both are virtual nginx servers on same machine.

serverX - proxy handler is enabled by using the directive (proxy_cache)
serverY - custom handler is used which simply outputs a text which serverX forwards to the client to a particular port say 8111

Below is the sample nginx.conf fragments for each of the server
###############################################################

#serverX (1st server)
server
{
location /cache1/
{
...
proxy_pass http://localhost:8111/custom/;
...
}

}

#serverY (2nd server)
server
{
location /custom/
{
#this is to invoke my custom handler for 2nd server
my_custom_module_directive;
}
}
###############################################################

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).

Please let me know if you need further clarifications.

PS -
cache has been enabled and verified (used the directives - proxy_cache_path, proxy_cache, proxy_cache_valid)
content-type and other response headers from serverY is properly assigned.
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: 315
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