我想用树莓派搭一个文件服务器,然后通过 NGINX 访问,中间遇到了个用户权限的问题,小白一枚诚心请教...

2016-09-11 21:38:02 +08:00
 itabas016

主页访问正常:

  • share
  • book
  • music
  • image
  • film

访问子链接就报 403 error:

2016/09/11 18:39:18 [error] 22904#0: *1 open() "/media/pi/ITABAS/Book" failed (13: Permission denied), 
client: 192.168.11.201, server: ~^\d+\.\d+\.\d+\.\d+$, request: "GET /Book HTTP/1.1",...

外接硬盘目录结构及权限, 用户 pi

pi@raspberrypi:/ $ ls -al /media/pi/ITABAS/
total 8
drwx------  1 pi   pi   4096 Sep 10 01:10 .
drwxr-x---+ 3 root root 4096 Sep  8 22:13 ..
drwx------  1 pi   pi    176 Sep 11 19:40 Book
drwx------  1 pi   pi    168 Sep 11 01:21 download
drwx------  1 pi   pi      0 Sep  9 23:07 Film
drwx------  1 pi   pi    144 Sep 10 00:13 Image
drwx------  1 pi   pi    160 Sep 10 00:12 Music
drwx------  1 pi   pi      0 Sep  9 23:07 Photo
sudo chown -R www-data:www-data /media/pi/ITABAS/
sudo chmod 755 /media/pi/ITABAS/

执行后权限无变化

Index 主页目录及权限

pi@raspberrypi:/ $ ls -al /var/www/nas/
total 16
drwxr-xr-x 2 www-data www-data 4096 Sep 11 18:18 .
drwxr-xr-x 5 root     root     4096 Sep 11 12:30 ..
-rw-r--r-- 1 www-data www-data  451 Sep 11 18:18 index.html
-rw-r--r-- 1 www-data www-data  840 Sep 11 16:58 index.html.bk

NGINX 站点 conf 配置, nginx 默认用户 www-data

server {
        listen 8080 default_server;

        root /media/pi/ITABAS;

        server_name ~^\d+\.\d+\.\d+\.\d+$;

        location / {
                root /var/www/nas/;
                index index.html index.htm index.nginx-debian.html;
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

         location /download {
                autoindex on;
                autoindex_exact_size on;
                autoindex_localtime on;
                allow   all;
        }

        location /Book {
                autoindex on;
                autoindex_exact_size on;
                autoindex_localtime on;
                allow   all;
        }
 }

另外我的外接硬盘还做了 samba, 把 www-data 加进去也没有反应...

[usbhdd]
    comment = HDD Media Storage
    path = /media/pi/ITABAS/
    browseable = yes
    writable = yes
    create mask = 0664
    directory mask = 0775
    valid users = root pi www-data

麻烦大家指点一下,谢谢~

5454 次点击
所在节点    NGINX
9 条回复
misaka19000
2016-09-11 22:47:06 +08:00
如果 Nginx 中不使用外接硬盘而是直接访问本地的文件能够访问吗?
itabas016
2016-09-12 10:26:22 +08:00
@misaka19000 我的 index 主页是本地文件, www-data 可以访问。链接是指向的外接硬盘目录,用户是 pi, 我执行
```
sudo chown -R www-data:www-data /media/pi/ITABAS/
sudo chmod 755 /media/pi/ITABAS/
```
但是文件所有者权限却没有改变, 还是 pi
arcas
2016-09-12 10:48:23 +08:00
@itabas016 外置硬盘文件系统不兼容。
fangdingjun
2016-09-12 10:49:43 +08:00
ntfs-3g 挂载的 NTFS 分区,挂载后是无法改变所有者和权限的, 但是可以在挂载时指定

建议让 nginx 以 pi 用户运行
misaka19000
2016-09-12 11:06:39 +08:00
@itabas016 那直接使用 pi 用户启动 Nginx 试一下
itabas016
2016-09-12 11:20:58 +08:00
@arcas
@fangdingjun
@misaka19000 我回家试一试。多谢~
ety001
2016-09-12 13:33:01 +08:00
你用的是 pi 用户挂载的外设,所以权限就不会修改成功的。建议修改 nginx 配置文件 nginx.conf 中的用户项,让 nginx 以 pi 用户身份启动。
cike
2016-09-12 13:45:23 +08:00
有没有关掉 selinux ?
itabas016
2016-09-12 23:27:57 +08:00
@fangdingjun
@misaka19000 用 pi 启动可以 work 了, thx

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/305513

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX