How to make nginx fail if it can't write to cache dir.

Francis Daly francis at
Tue Feb 1 08:42:52 UTC 2022

On Sun, Jan 30, 2022 at 04:01:31AM -0500, unikron wrote:

Hi there,

> The error on a base dir is critical to all cache requests, so no request
> will succeed.

Yes. In your case, *all* requests are cache requests, so you want your
process to fail entirely. But in the general case, all of the non-cache
requests could be handled correctly while the administrator fixes their
cache-request configuration, so hard-failing is probably not appropriate

> I know I can write a script to monitor it, but it seems like the wrong
> approach.
> I would like to have the option for nginx to stop if it can't do the job as
> should, But I guess that if no one answered with that kind of solution, it
> doesn't exist in nginx.

I believe that you are correct: stock nginx does not provide this
facility today.

If it is important to your use case, it should be possible for you to
modify your nginx source code to do the "stop the process entirely"
that you want.

For what it's worth: the log line that you showed seems to
only be possible when one of the functions: ngx_create_path() or
ngx_ext_rename_file() is called; and that does not happen in many places
in the source.

If you can (encourage someone to) modify the code to hard-exit when your
circumstances happen, then you will have a "quick fix" for your use case.

After that, maybe the change (controlled by some config option) would
be interesting to the wider project; in that case, you might not have
to maintain the change as an external patch that you apply-or-adapt to
every future nginx release that you want to use.

(I don't know if this particular facility could easily be provided by
an external module.)

In the main, at least one of the reasons why a facility does not exist
for general use, is that no-one has yet considered it important enough
to arrange that the code be written and shared.

You've found such a case that would be convenient for you if it already
existed; it doesn't; so you get to decide how important it is to you to
make it exist.

"Scripting around it" is a perfectly valid option too, of course. Others
exist as well, no doubt.

That probably isn't the answer that you want; but maybe it will help you
search for alternate solutions, once you know that the "easy" option is
not there.


Francis Daly        francis at

More information about the nginx mailing list