open()“/var/lib/nginx/cache/fastcgi/3/d0/bce7bdb8e2c388c7675c97c7324efd03”失败(13:权限被拒绝)

open()“/var/lib/nginx/cache/fastcgi/3/d0/bce7bdb8e2c388c7675c97c7324efd03”失败(13:权限被拒绝)

我正在尝试添加缓存为了代理人&快速CGI但当我尝试查看网站上的任何页面时,它就会失败500内部服务器错误当我尝试在日志中搜索任何错误时,我发现nginx无法访问缓存文件夹:


快速CGI2023/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"
代理人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;
}

我试图更改权限/var/lib/nginx/缓存&

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

和所有者/var/lib/nginx/缓存根(我试过了nginx用户也一样):

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

编辑:我刚刚发现/var/lib/nginx/缓存应该给予许可执行为了用户&团体&其他

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

但一旦我重新启动nginx,它会再次抛出这些错误

答案1

错误消息类型

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

通常与 SELinux 或 AppArmor 相关。

您需要遵循文档将 NGINX 和 NGINX Plus 与 SELinux 结合使用或根据您的需要采用它。

类似问答

相关内容