在配置文件 /etc/httpd/conf/httpd.conf 中一共有三个地方需要修改,这里以目标目录 /pub/meetings/test 为例。
4.1 修改参数 “DocumentRoot”
关于这个参数的一部分原文长这样:
[[email protected] ~]$ cat /etc/httpd/conf/httpd.conf | grep “DocumentRoot”
DocumentRoot: The directory out of which you will serve your
DocumentRoot “/var/www/html”
access content that does not live under the DocumentRoot.
可以看到,它默认的目录位于 /var/www/html 。
接下来,我们注释掉原文,把它改成我们需要的/pub/meetings/test目录。
[[email protected] ~]$ sudo vi /etc/httpd/conf/httpd.conf
…
DocumentRoot: The directory out of which you will serve your
DocumentRoot “/var/www/html”
DocumentRoot “/pub/meetings/test”
access content that does not live under the DocumentRoot.
…
4.2 修改目录参数
[[email protected] ~]$ sudo vi /etc/httpd/conf/httpd.conf
…
Relax access to content within /var/www.
AllowOverride None
Allow open access:
Require all granted
…
4.3 再次修改目录参数
[[email protected] ~]$ sudo vi /etc/httpd/conf/httpd.conf
…
Further relax access to the default document root:
Possible values for the Options directive are “None”, “All”,
or any combination of:
Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
…
4.4 同样地,再次重启http服务,确保我们的更改立即生效
$ sudo systemctl restart httpd
经过这样一番设置,在浏览器看到的,应该就是 /pub/meetings/test 的目录结构了。
4.5 如果第(4)步不能正常访问到目标目录,那么,通常是由于Apache用户关于该文件夹的权限太低(apache的用户:apache,运行apache的组:apache,默认权限为750)。
我们需要给它作以下设置赋予权限:
755或者777均可 (二选一:最好是777,因为它具有写权限)
755: rwxr-xr-x
$ sudo chmod -R 755 /pub/meetings/
777: rwxrwxrwx
$ sudo chmod -R 777 /pub/meetings/
再重启httpd服务,就可以搞定了。
4.6 其它一些细节设置
默认的设置有一些地方需要修改:不支持中文、显示优化等等。
具体执行的操作是将默认的设置参数按照如下方式修改,增加4个参数:
$ sudo vi /etc/httpd/conf.d/autoindex.conf
…
#IndexOptions FancyIndexing HTMLTable VersionSort
IndexOptions FancyIndexing HTMLTable VersionSort FoldersFirst Charset=UTF-8 NameWidth=* XHTML
…
其中,FoldersFirst 保证显示结果中的文件夹名称居于前面,UTF-8字符集有效地解决了中文显示的问题,“NameWidth=*”的作用不详。
4.7 加载 NTFS 格式的分区时遇到的问题
按以上方法对 NTFS 格式的分区所在的目录进行设置,并不能浏览每一个分区内的内容,只能看到分区的根目录下的内容。
根据系统报告可以进行修复:
[[email protected] ~]$ journalctl -xe
…
4月 18 16:33:23 localhost.localdomain dbus[733]: [system] Successfully activated service ‘org.fedoraproject.Setroubleshootd‘
4月 18 16:33:24 localhost.localdomain setroubleshoot[32222]: failed to retrieve rpm info for /mnt/Disk2T/L
4月 18 16:33:24 localhost.localdomain setroubleshoot[32222]: SELinux is preventing /usr/sbin/httpd from read access on the directory
/mnt/Disk2T/L. For complete SELinux messages. run se
4月 18 16:33:24 localhost.localdomain python[32222]: SELinux is preventing /usr/sbin/httpd from read access on the directory /mnt/Disk2T/L.
***** Plugin catchall_boolean (89.3 confidence) suggests ******************