-1

Suddenly I started getting the following error when I try to restart nginx:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: [emerg] mkdir() "/var/run/nginx-cache/site1" failed (2: No such file or directory)

nginx: configuration file /etc/nginx/nginx.conf test failed

So I have to create nginx-cache folder and make www-data the owner of it to restart nginx, but I'm hoping there's a better way.

For your information, my nginx configuration is as follows:

fastcgi_cache_path /var/run/nginx-cache/site1 levels=1:2 keys_zone=site1:100m inactive=60m;
fastcgi_cache_path /var/run/nginx-cache/site2 levels=1:2 keys_zone=site2:100m inactive=60m;
fastcgi_cache_path /var/run/nginx-cache/site3 levels=1:2 keys_zone=site3:100m inactive=60m;
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

server {
....
location ~ \.php$ {
....
 include fastcgi_params;
 fastcgi_pass unix:/var/run/php5-fpm.sock;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 fastcgi_cache_bypass $skip_cache;
 fastcgi_no_cache $skip_cache;
 fastcgi_cache site1;
 fastcgi_cache_valid  60m;
}

server {
....
location ~ \.php$ {
....
 include fastcgi_params;
 fastcgi_pass unix:/var/run/php5-fpm.sock;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 fastcgi_cache_bypass $skip_cache;
 fastcgi_no_cache $skip_cache;
 fastcgi_cache site2;
 fastcgi_cache_valid  60m;
}

server {
....
location ~ \.php$ {
....
 include fastcgi_params;
 fastcgi_pass unix:/var/run/php5-fpm.sock;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 fastcgi_cache_bypass $skip_cache;
 fastcgi_no_cache $skip_cache;
 fastcgi_cache site3;
 fastcgi_cache_valid  60m;
}

Any help would be greatly appreciated!

Jun
  • 3
  • 1

1 Answers1

0

You haven't told what is your distribution. However, on Debian at least, /var/run is a symlink to /run, where the filesystem type is tmpfs.

tmpfs isn't a permanent filesystem, so it is destroyed on every reboot. Therefore you have to either make a script that creates those directories on boot, or use some other directory on permanent storage for your fastcgi_cache_path.

I would prefer changing the path to a permanent storage, so that the cache would still be there after reboot. And then let Linux OS disk cache handle in-memory caching of the files.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63