【问题标题】:s3fs volume exposed via nginx通过 nginx 暴露的 s3fs 卷
【发布时间】:2019-07-11 21:16:32
【问题描述】:

我正在使用命令将 S3 存储桶安装到 Ubuntu VM

root@factory:~# s3fs my-bucket /mnt/s3-bucket -o passwd_file=/etc/.passwd-s3fs -o noatime -o allow_other -o uid=1000 -o gid=1000 -o use_cache=/tmp -o default_acl=public-read-write

此卷已正确安装到 VM。还可以将文件从/mnt/s3-bucket/* 复制到任何其他位置。

root@factory:~# ls -alh /mnt/s3-bucket/
total 56K
drwxrwxrwx 1 ubuntu ubuntu    0 Jan  1  1970 .
drwxr-xr-x 3 root   root   4.0K Jul 19 20:30 ..
-rw-r----- 1 ubuntu ubuntu  50K Jul 22 15:04 controller_1.34.0.tar
drwxr-x--- 1 ubuntu ubuntu    0 Jul 22 15:04 firmware

不知道为什么这些文件归ubuntu:ubuntu所有

我正在尝试通过 Nginx 提供此位置以下载这些文件。

但是当我点击文件名时,我得到403 Forbidden

试图更改文件权限

root@factory:~# chown -R root:root /mnt/s3-bucket
chown: changing ownership of '/mnt/s3-bucket/controller_1.34.0.tar': Input/output error
chown: changing ownership of '/mnt/s3-bucket/fixture_controller_2.1.3.tar': Input/output error
chown: changing ownership of '/mnt/s3-bucket': Input/output error
root@factory:~#

试图从虚拟机创建文件 root@factory:~# touch /mnt/s3-bucket/test.txt touch: '/mnt/s3-bucket/test.txt'的设置次数: 没有那个文件或目录

nginx.conf:

server {
    listen         8080 default_server;
    server_name    localhost;
    keepalive_timeout 70;
    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/x-javascript application/javascript text/xml application/xml application/xml+rss text/javascript;

    location /s3 {
        alias /mnt/s3-bucket;
        autoindex on;
    }
}

来自Nginx 的日志:

2019/07/24 13:45:10 [error] 10777#10777: *2 open() "/mnt/s3-bucket/fixture_controller_2.1.3.tar" failed (13: Permission denied), client: 13.12.18.18, server: localhost, request: "GET /s3/fixture_controller_2.1.3.tar HTTP/1.1", host: "43.3.7.96:8080", referrer: "http://43.3.7.96:8080/s3/"
2019/07/24 13:45:18 [error] 10777#10777: *2 open() "/mnt/s3-bucket/controller_1.34.0.tar" failed (13: Permission denied), client: 13.12.18.18, server: localhost, request: "GET /s3/controller_1.34.0.tar HTTP/1.1", host: "43.3.7.96:8080", referrer: "http://43.3.7.96:8080/s3/"

我错过了什么?我如何通过 Nginx 提供可下载的 S3 文件

【问题讨论】:

  • 至少有两种其他可能更好的方法来处理这个问题。第一个是签署 URL 并重定向到它们,让 S3 直接为负载提供服务。这将为您节省一些带宽成本。如果出于某种原因您不想这样做,那么接下来要尝试的是直接代理 S3。我这样说是因为我认为您会发现 S3 FUSE 驱动程序本质上有点棘手,并且偶尔会让您失败。
  • 每个单独的 URL 都会即时签名。您可以提供任何您想要的服务,但您需要一些脚本服务器端。 (肯定有人为此提供了 Nginx 的 Lua 脚本?)
  • 请发布您使用的nginx 配置。还有ls -alh /mnt/s3-bucket的输出
  • 尝试从容器内部执行chown -R root:root /mnt/s3-bucket,然后看看它是否有效
  • 另外,如果您在容器内或主机上运行s3fs,请告知使用?

标签: nginx amazon-s3 s3fs


【解决方案1】:

S3 存储桶中的文件归 ubuntu:ubuntu 所有,因为 S3 存储桶是使用参数 -o uid=1000 -o gid=1000 挂载的。这些是用户 ubuntu 和组 ubuntu 的 ID。

处理 http 请求的 nginx 工作进程以其他用户身份运行。通常是 www-data

如果您想让 nginx 访问 S3 存储桶中的文件,您必须将 uidgid 替换为 www-data。

id -u www-data 显示 uidid -g www-data 显示 gid

【讨论】:

    猜你喜欢
    • 2019-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-20
    相关资源
    最近更新 更多