apache2外部磁盘权限

时间:2014-12-30 22:30:12

标签: apache ubuntu apache2 file-permissions symlink

目前我的电脑上有我的所有项目的硬盘驱动器,我希望我的apache服务器链接我的所有项目通过虚拟主机,但给我访问被拒绝,是问题是因为它不是主磁盘,我可以做到了吗?

例如:

我使用的是ubuntu 14.04

root@MS-7817:/# cat /etc/apache2/sites-available/demo.conf 
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName demo.local

    DocumentRoot /home/me/public_html/demo
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /home/me/public_html/demo/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

网站已启用:

me@MS-7817:/etc/apache2/sites-enabled$ ll
total 8
drwxr-xr-x  2 root root 4096 dic 30 17:01 ./
drwxr-xr-x 10 root root 4096 dic 28 03:13 ../
lrwxrwxrwx  1 root root   35 dic 27 20:02 000-default.conf -> ../sites-available/000-default.conf
lrwxrwxrwx  1 root root   28 dic 30 17:01 demo.conf -> ../sites-available/demo.conf

执行:

$ ln -s /media/myuser/projectdisk/demo/www/ /home/myuser/public_html/demo

申请主持人:

root@MS-7817:/# cat /etc/hosts
127.0.0.1   localhost
127.0.1.1   MS-7817

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

127.0.0.1   demo.local

文件存在:

root@MS-7817:/# cd /home/me/public_html/demo
root@MS-7817:/home/me/public_html/demo# ll
total 100
drwxrwxr-x 2 www-data www-data  4096 dic 30 16:30 ./
drwxrwxr-x 5 me       me        4096 dic 29 13:49 ../
-rw-rw-r-- 1 me       me        12921 dic 30 16:30 index.php

我使用了正确的权限:

me@MS-7817:/$ id
uid=1000(me) gid=1000(me) grupos=1000(me),4(adm),24(cdrom),27(sudo),30(dip),33(www-data),46(plugdev),108(lpadmin),124(sambashare)

重新启动apache:

me@MS-7817:/$ sudo service apache2 restart
[sudo] password for me: 
 * Restarting web server apache2
 * 

但无法访问http://demo.local/

Forbidden

You don't have permission to access / on this server.
Apache/2.4.7 (Ubuntu) Server at demo.local Port 80

2 个答案:

答案 0 :(得分:1)

它们是文件权限问题,默认的ubuntu挂载磁盘对当前用户www-data具有只读权限而没有读取权限:

me@machine:~$ sudo -u www-data ls -la /media/me
ls: no se puede abrir el directorio /media/me: Permiso denegado

此处找到的解决方案:https://superuser.com/questions/174776/modify-fstab-entry-so-all-users-can-read-and-write-to-an-ext4-volume,我允许驾驶并准备好了:)

me@machine:~$ sudo chmod 777 /media/me -R
me@machine:~$ sudo -u www-data ls -la /media/me
total 12
drwxrwxrwx+  3 root root 4096 ene 14 15:33 .
drwxr-xr-x   3 root root 4096 dic 25 13:41 ..
drwxrwxrwx  22 me   me   4096 ene  2 00:36 2TB

答案 1 :(得分:0)

我有类似的问题
我想让apache访问我的外部硬盘上的文件,
但是我收到了错误403权限被拒绝。

我通过更改/ etc / apache2 / envvars中的以下两行来解决此问题
(sudo gedit / etc / apache2 / envvars)

export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data

我将“ www-data”替换为“我的用户名”,如下所示:

export APACHE_RUN_USER=my user name
export APACHE_RUN_GROUP=my user name

此后,apache可以访问文件