Fastcgi seems to be caching error pages

Hello all,

I have had a site go down a few times and setup uptime checks for it thinking that it would help me know when it was down so I could do a redeploy or server setup run which seemed to fix.

It happened again this morning but my uptime checker was saying the site was fine. In chrome the site was giving a 502 but it was working on FF and other computers and phones.

I closed up/quit chrome and reopened and the site worked so this was a local caching issue.

I did some digging and found the below at:

Is the default Trellis settings for all pages to be cached including error pages? Can someone help with the commands to stop the caching of 502 errors?


I managed to figure this out myself. Nginx really does cache the knowledge that the upstream server is inaccessible.

To fix this I changed my cache config from  `proxy_cache_valid any 5m;`  to  `proxy_cache_valid 5m;`  Removing  `any`  implies you only want to cache 200, 301, and 302 responses.

[share]([improve this answer](

answered Mar 11 '15 at 19:41
* The same applies to all  `*_cache_valid`  directives, including  `uwsgi_cache_valid`  for  `uwsgi_cache` , and  `fastcgi_cache_valid`  for  `fastcgi_cache` . Just clarifying this somewhat already-obvious point for ease of discovery via web searches. – [davidjb]( [Mar 16 '15 at 2:41](

It looks like Trellis already does what those answers say:

fastcgi_cache_valid {{ item.value.cache.duration | default(nginx_cache_duration) }};
nginx_cache_duration: 30s

That’s the default value so we aren’t using any. And the docs say:

If only caching time is specified
fastcgi_cache_valid 5m;
then only 200, 301, and 302 responses are cached.

Thanks Scott… I found those settings and I have not changed them so I have no idea what could be causing this.

Any idea what else could cause this? A co-worker first told me about it, I tried on my default browser and also received a 502 and then opened up FF, which I rarely use, and it loaded fine.

I will check out the headers on the working and not working browsers next time this happens and hopefully it will give a clue.


Ok this happened again and I checked the headers showed that caching was not the issue. I have no idea what this could be and will check the logs.


1 Like

Re-deploying solves the issue if that helps anyone come up with any ideas of what could be causing this.


This topic was automatically closed after 42 days. New replies are no longer allowed.