-1

I am trying to add Caching for Proxy & FastCGI but once i try to view any page on the site it fails with 500 Internal Server Error and when i tried searching my logs for any errors i found that nginx can't access the cache folder:


FastCGI: 2023/10/29 10:53:30 [crit] 591459#591459: *1 open() "/var/lib/nginx/cache/fastcgi/3/d0/bce7bdb8e2c388c7675c97c7324efd03" failed (13: Permission denied), client: ::1, server: localhost, request: "GET /phpmyadmin/index.php HTTP/1.1", host: "localhost"
Proxy: 2023/10/29 10:52:25 [crit] 591351#591351: *1 open() "/var/lib/nginx/cache/expressjs/9/f3/f3bfeb3387c38d7a557be4d864d67f39" failed (13: Permission denied), client: ::1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"

/etc/nginx/nginx.conf:

http {
    proxy_cache_path /var/lib/nginx/cache/expressjs  levels=1:2 keys_zone=expressjs-cache:30m max_size=192m;
    fastcgi_cache_path /var/lib/nginx/cache/fastcgi  levels=1:2 keys_zone=php-cache:30m max_size=192m;
}

/etc/nginx/conf.d/expressjs.conf:

location ~ ^/dev {
    ### ........
    proxy_cache expressjs-cache;
    proxy_cache_key $host$request_uri;
    proxy_cache_valid any 10m;
    proxy_cache_valid 401 5s;
    proxy_cache_valid 403 5s;
    proxy_cache_valid 404 5s;
    proxy_cache_valid 500 5s;
    proxy_cache_valid 501 5s;
    proxy_cache_valid 502 5s;
    proxy_cache_bypass 0;
    proxy_no_cache 0; # $http_upgrade
}

/etc/nginx/conf.d/fastcgi.conf:

location ~ ^/phpmyadmin {
    ### ........
    fastcgi_cache php-cache;
    fastcgi_cache_key "$scheme:$request_method~$host/$request_uri";
    fastcgi_cache_valid any 10m;
    fastcgi_cache_valid 401 5s;
    fastcgi_cache_valid 403 5s;
    fastcgi_cache_valid 404 5s;
    fastcgi_cache_valid 500 5s;
    fastcgi_cache_valid 501 5s;
    fastcgi_cache_valid 502 5s;
}

i tried to change permissions of /var/lib/nginx/cache to read&write:

sudo chmod -R u=rw /var/lib/nginx/cache
sudo chmod -R g=rw /var/lib/nginx/cache
sudo chmod -R o=rw /var/lib/nginx/cache

and owner of /var/lib/nginx/cache to root (and i tried nginx user too):

sudo chown -R root:root /var/lib/nginx/cache

EDIT: i just found that /var/lib/nginx/cache should be given permission exec for User&Group&Other:

sudo chmod -R u=rwx /var/lib/nginx/cache
sudo chmod -R g=rwx /var/lib/nginx/cache
sudo chmod -R o=rwx /var/lib/nginx/cache

but once i restart nginx, it throws those errors again

Zorono
  • 3
  • 4

1 Answers1

0

Error messages of type

open() "<file>" failed (13: Permission denied)

are usually related to SELinux or AppArmor.

You'll need to follow the documentation Using NGINX and NGINX Plus with SELinux or adopt it for your needs.

Similar Q&A

U880D
  • 1,169