0

I am using nginx as a reverse proxy.

Is it possible somehow to access response page content as a variable to disable caching for a pages that have specific word in content (not in header) WITHOUT modifying backend?

Any way would be appreciated including inline perl, lua or even piping page content to php script that would parse the content.

I can even make a dirty code hack if someone could show me a source file which parses page response and any idea what I can change in that file (add no cache headers or just hack some other variable that corresponds caching)

POMATu
  • 210
  • 2
  • 10
  • There's no obvious way to do this. It would slow the server down so dramatically that it's almost certainly not worth the trouble. What are you trying to accomplish with this scheme? There is probably some better way to do it. – Michael Hampton Feb 27 '18 at 17:02
  • I'm not sure why you would like a cache at all if you want to slow down your server by parsing each response body. There are filter modules like the `nginx_substitutions_filter`but those are not allowed in an IF block. You made it clear that in your case there is no way to modify the backend. But I would still try to find a solution that those pages do not get into the cache in the first place eg. by adding/parsing url a parameter. Thinking of (real) dirty hacks … constantly grep nginx cache directory and chown matched cache files so nginx user has no acces and can't overwrite them anymore. – Bob Feb 27 '18 at 20:42
  • @Bob the problem is that the backend shows captcha sometimes on any page. And that captcha gets cached so I cannot access index.php even after I pass that captcha. It does not redirect to page with captcha it can show captcha at index.php or image.jpg. So it's not possible to even chown that files. Is it possible to disable nginx cache completely and force browser to cache all static files by overwriting the header? maybe I can use squid as the load balancer, may it help in my case? – POMATu Mar 03 '18 at 15:42
  • @MichaelHampton Maybe I can write some script that resets cache of specific page in nginx directory when I get captcha cached? But what is the better way to cancel cache of specific page in nginx? – POMATu Mar 03 '18 at 18:01
  • Your page should be sending a response header to prevent caching, i.e. `Cache-Control: no-cache`. – Michael Hampton Mar 03 '18 at 19:44

0 Answers0