在 Kubernetes 上使用 NFS 共享卷时出现 Nginx 403 禁止错误

Nginx 403 Forbidden error while using NFS-Shared Volumes on Kubernetes

我正在我的集群上测试共享持久卷。我在 AWS 上创建了一个 EKS 集群,我在其中一个节点上安装了 NFS 服务器,并为其创建了 PV 和 PVC。我能够使用多个应用程序安装卷。但是我无法从 Nginx 服务器访问 html 文件,因为它抛出 403 Forbidden Error.

下面是我的 NFS 服务器 nginx 的截图,我的数据在上面挂载了权限

我已经在我的集群上部署了 Nginx 作为 Pod。下面是我的 Nginx 配置文件

nginx.conf

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

conf.d/default.conf

server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

nginx pod 日志

   *22 directory index of "/usr/share/nginx/html/test/" is forbidden, client: 10.14.20.128, server: localhost, request: "GET /test/ HTTP/1.1", host: "*.amazon.com"
    getuser?index=0 HTTP/1.1", host: "3.124.54.114:80"
    10.14.20.178 - - [07/Jun/2021:08:59:10 +0000] "GET /config/getuser?index=0 HTTP/1.1" 404 153 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0" "-"
    2021/06/07 09:03:30 [error] 30#30: *1788 directory index of "/usr/share/nginx/html/test1/" is forbidden, client: 10.14.21.153, server: localhost, request: "GET /test1/ HTTP/1.1", host: ".elb.amazonaws.com"
    10.14.21.153 - - [07/Jun/2021:09:03:30 +0000] "GET /test1/ HTTP/1.1" 403 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36" "-"
    10.14.21.153 - - [07/Jun/2021:09:12:30 +0000] "GET / HTTP/1.1" 403 153 "-" "Mozilla/5.0 (Windows NT 5.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1" "-"
    2021/06/07 09:12:30 [error] 30#30: *1953 directory index of "/usr/share/nginx/html/" is forbidden, client: 10.14.21.153, server: localhost, request: "GET / HTTP/1.1", host: "35.157.4.133"
    10.14.21.153 - - [07/Jun/2021:09:12:30 +0000] "GET /HNAP1/ HTTP/1.1" 404 153 "http://35.157.4.133/" "Mozilla/5.0 (Windows NT 5.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1" "-"
    2021/06/07 09:12:30 [error] 30#30: *1954 "/usr/share/nginx/html/HNAP1/index.html" is not found (2: No such file or directory), client: 10.14.21.153, server: localhost, request: "GET /HNAP1/ HTTP/1.1", host: "35.157.4.133", referrer: "http://35.157.4.133/"
    2021/06/07 09:55:33 [error] 30#30: *2729 directory index of "/usr/share/nginx/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
    127.0.0.1 - - [07/Jun/2021:09:55:33 +0000] "GET / HTTP/1.1" 403 153 "-" "curl/7.64.0" "-"
    2021/06/07 10:02:47 [error] 30#30: *2828 directory index of "/usr/share/nginx/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
    127.0.0.1 - - [07/Jun/2021:10:02:47 +0000] "GET / HTTP/1.1" 403 153 "-" "curl/7.64.0" "-"

我能够解决问题。当您在 EC2 实例上安装 NFS 服务器(将其视为主服务器)时,我们必须确保在其他 EC2 实例(将其视为客户端)上安装 NFS 服务器路径并应用我们将能够访问的相关 Chmod 权限通过 nginx

的文件