1

我有一个简单的 Flask/Nginx 服务器和 3 个文件位置/opt/hosting/files

[adam@localhost]$ namei -om /opt/hosting/files
    f: /opt/hosting/files
     dr-xr-xr-x root  root  /
     drwxr-xr-x root  root  opt
     drwxr-xr-x root  root  hosting
     drwxr-xr-x nginx nginx files

在文件夹中files,我有 3 个文件:两个图像和一个更大的 zip 文件:

[adam@localhost]$ ls -lh /opt/hosting/files/
total 424M
-rwx-----x. 1 nginx nginx  19K 03-06 01:29 file1.jpg
-rwx-----x. 1 nginx nginx  18M 03-06 03:34 file2.png
-rwxr-xr-x. 1 nginx nginx 406M 07-07 13:07 file3.zip

我正在提供这些文件,而前两个似乎没有问题,我403 Forbidden通过 www 和使用 wget 获取 zip 文件。我认为目录权限设置正确,因为其他两个文件都很好。Zip 文件的属性甚至更高,因此这也不应该成为问题。

我尝试将chown root:rootandchown 777用于文件和文件夹,但无论如何都无法访问该文件。进行更改后,我正在重新启动 nginx sudo systemctl restart uwsgi。SELinux 显示Enforcing.

这里有什么问题?

4

1 回答 1

4

知道了。在这里阅读tinesoft 的评论让我检查了文件的 SELinux 上下文(是的,我正在运行 CentOS,忘了提及),它是:

[adam@localhost]$ ls -lZ /opt/hosting/files
-rwx-----x. nginx nginx unconfined_u:object_r:httpd_sys_content_t:s0 file1.jpg
-rwx-----x. nginx nginx unconfined_u:object_r:httpd_sys_content_t:s0 file2.png
-rwxr-xr-x. nginx nginx unconfined_u:object_r:user_home_t:s0 file3.zip

然后,按照RedHat 的 SELinux 文档,我设法将 SELinux 上下文的类型从更改user_home_thttpd_sys_content_t使用

sudo chcon -t httpd_sys_content_t file3.zip

就是这样。

于 2017-07-07T12:47:33.097 回答