已经两天了,还没有解决方案,所以我寻求帮助。我已经搜索并尝试过了,已经解决了一些问题,但还有最后一件事。
这就是我想要做的:将 apache2 的默认目录从 /var/www/html 更改为 /media/pi/storage/root_folder/
我已经按照这个教程操作了 >https://help.ubuntu.com/community/ApacheMySQLPHP#Virtual_Hosts
在虚拟主机部分下,我在 /home/pi/Desktop/ 创建了一个测试 html,并且由于(我假设)正确的权限它可以工作。
现在,当我在 /media/pi/storage/root_folder/ 执行完全相同的操作并重新加载网页时,我收到禁止错误消息,表明我的硬盘驱动器(使用 ext4 格式化)存在权限问题(再次,我认为这是正确的)
类似这样的方法有用吗?
sudo chown -R USER:USER /media/pi/storage/root_folder/
或者chgrp -R www-data /username/
chmod -R 2750 /username/
,或者是其他方法?
我不知道需要什么命令,如果能一步一步地说明我将不胜感激
最后,我如何让这些权限在将来应用于任何新的子目录和文件,以便我不再遇到相同的禁止错误?
我很感激任何帮助,谢谢大家。
虚拟主机配置文件:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /media/pi/storage/root_folder/
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Apache 错误日志片段:
[Sun Dec 17 05:29:33.304748 2017] [core:error] [pid 951:tid 1836053552] (13)Permission denied: [client 192.168.1.137:43006] AH00035: access to / denied (filesystem path '/media/pi/storage') because search permissions are missing on a component of the path
输出ls -ld /media /media/pi /media/pi/storage
:
drwxr-xr-x 3 root root 4096 Nov 29 02:57 /media
drwxr-x---+ 3 root root 4096 Dec 17 05:28 /media/pi
drwxr-xr-x 4 pi pi 4096 Dec 16 20:31 /media/pi/storage
答案1
您还必须允许 Apache 访问该目录。默认情况下,Apache 仅允许访问/var/www
和/usr/share
;此访问权限由以下块授予/etc/apache2/apache2.conf
:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
因此,您必须在 Apache 配置中的某处添加类似的块,以授予访问权限/media/pi/storage/root_folder/
:
<Directory /media/pi/storage/root_folder/>
Require all granted
</Directory>
如果您已经有一个<Directory /media/pi/storage/root_folder/>
块,例如在您的虚拟主机配置文件中,只需向Require all granted
其中添加指令就足够了。
此外,错误日志显示 Apache (IE(www-data
用户)对 的组件没有读取或搜索权限/media/pi/storage
。 的输出ls -ld /media /media/pi /media/pi/storage
显示/media
和/media/pi/storage
都具有 755 权限,因此罪魁祸首一定是/media/pi
。由于/media/pi
正在使用访问控制列表+
(如输出中的符号所示ls -ld
),我们授予www-data
读取和搜索权限
sudo setfacl -m u:www-data:rx /media/pi