I want to set up Nginx as my web server. I want to have image files cached in the memory (RAM) rather than disk. I am serving a small page and want a few images always served from RAM. I don't wish to use Varnish (or any other such tools) for this as I believe Nginx has a capability to cache contents into RAM. I am not sure as to how I can configure Nginx for this? I did try a few combinations but they didn't work. Nginx uses disk all the time to get the images.
For example, when I tried Apache benchmark to test with following command:
ab -c 500 -n 1000 http://localhost/banner.jpg
I get the following error:
socket: Too many open files (24)
I guess this means Nginx is trying to open too many files simultaneously from the disk and OS is not allowing this operation. Can anyone please suggest me a correct configuration?
If it's static content then it will be cached in memory by default (unless there isn't any memory left), just not by nginx, but OS - all that will be left disk-side will be stat().
If you want 100% memory solution you can just configure ramdisk and serve data from there.
Once the server has read a file from the disk, it will be cached to ram (and will be replaced by diffrent file if you are out of ram), the problem is with your account limit, you can't open so much files (run 'ulimit -a'),
If you want to change this limit - read about /etc/security/limits.conf
So I know this is really old but, here goes.
A file cached in RAM is still a file !
Try to use Memcached cache module of Nginx instead. But still, 1000 concurrent connections is huge, do you think is your case?