nginx 和 nfs 权限被拒绝

nginx 和 nfs 权限被拒绝

我有两台 RHEL 7 机器。

我已经安装了 nginx 和 php-fpm,并设置了 nfs 挂载。我可以毫无问题地读取/写入 nfs 挂载,并且我还有另一个可以对其进行读写的应用程序服务器 (Apache Geronimo)。

当我安装 nginx 时,它会设置一个 nginx 用户,该用户是我在 NFS 文件服务器上创建的,具有相同的 uid 和 gid。

我能够使用 nginx 用户列出 nfs 客户端挂载上的文件。但是,当我尝试使用 nginx 从 nfs 提供静态 html 或动态 php 文件时,我收到权限错误:

*5 stat() "/usr/depot/repository/test.php" failed (13: Permission denied)
*5 open() "/usr/depot/repository/test.html" failed (13: Permission denied)

此外,我在 /usr/depot/testing 下创建了具有相同权限的文件夹(只是不是 nfs),并且运行良好。

这是客户端上的安装信息。

xxx.xxx.xxx.xxx:/mnt/repository on /usr/depot/repository type nfs4 (rw,nosuid,nodev,noexec,relatime,vers=4.0,rsize=524288,wsize=524288,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=xxx.xxx.xxx.xxx,local_lock=none,addr=xxx.xxx.xxx.xxx)

我看不出这个设置有什么问题,所以我不知道为什么 nginx 无法从 nfs 共享读取文件。

更新

好的,我刚刚禁用了 SELinux 重启,问题就解决了。现在的问题是如何配置 SELinux,以便 nginx 可以访问远程服务器。

答案1

在 RHEL 7 中,适用于 Apache 的相同 SELinux 策略也适用于 nginx。因此,您可以使用相同的布尔值:

httpd_use_nfs                  (off  ,  off)  Allow httpd to use nfs

设置正确的布尔值以允许 Web 服务器使用 NFS。

setsebool -P httpd_use_nfs 1

答案2

由于这是 Google 上针对该问题的第一个搜索结果,所以我想添加我的解决方案。

在我的情况下,SELinux 被禁用了,所以不是这个原因。我的问题是 php-fpm 以 apache 的形式运行。因此,在我的 CentOS 7 Web 服务器上(假设您按照 OP 在文件服务器上创建了一个 nginx 用户),我在 /etc/php-fpm.d/www.conf 中将用户和组更改为 nginx,然后重新启动 php-fpm。

相关内容