通过 nginx 公开的 s3fs 卷

s3fs volume exposed via nginx

我正在使用命令

将 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:~#

试图从 VM 创建文件 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 文件

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 显示 uid 并且 id -g www-data 显示 gid