Can I cache a static file forever in memory on Nginx?

I have Nginx running in a Docker container and it is serving some static files. Files will not change at run time - if they do change, the container will be stopped, the image will be rebuilt, and a new container will be launched.

So, to improve performance, it would be ideal if Nginx reads static files only once from disk, and then forever stores it from memory. I found some configuration options for configuring caching, but at least from what I saw, none of them provided this “forever” behavior that I am looking for.

Is this even possible? If so, how do I need to configure Nginx for this?

+4
source share
1 answer

The operating system performs caching by default. It is called the page cache . Alternatively, you can enable sendfile to avoid copying data between the kernel space and user space.

+3
source

Source: https://habr.com/ru/post/1650452/


All Articles