CentOS7安装配置httpd文件服务器

1. 安装配置httpd

$ sudo yum install httpd

2. 修改配置文件welcome.conf

将配置文件 /etc/httpd/conf.d/welcome.conf 以下选项的-号改为+号:

原文:Options -Indexes
修改后:Options +Indexes

3. 重启服务

$ sudo systemctl restart httpd

4. 更改http服务器的默认目录方法(可选)

在配置文件 /etc/httpd/conf/httpd.conf 中一共有三个地方需要修改,这里以目标目录 /pub/meetings/test 为例。

4.1 修改参数 “DocumentRoot”

关于这个参数的一部分原文长这样:

[User@Host ~]$ 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目录。

[User@Host ~]$ 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 修改目录参数

[User@Host ~]$ sudo vi /etc/httpd/conf/httpd.conf
...
#
# Relax access to content within /var/www.
#
#<Directory "/var/www">
<Directory "/pub/meetings">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>
...

4.3 再次修改目录参数

[User@Host ~]$ sudo vi /etc/httpd/conf/httpd.conf
...
# Further relax access to the default document root:
#<Directory "/var/www/html">
<Directory "/pub/meetings/test">
    #
    # 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 格式的分区所在的目录进行设置,并不能浏览每一个分区内的内容,只能看到分区的根目录下的内容。

根据系统报告可以进行修复:

[User@Host ~]$ 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   ******************
                                                      
                                                      If you want to allow httpd to use fusefs
                                                      Then you must tell SELinux about this by enabling the 'httpd_use_fusefs' boolean.
                                                      You can read 'None' man page for more details.
                                                      Do
                                                      setsebool -P httpd_use_fusefs 1
                                                      
                                                      *****  Plugin catchall (11.6 confidence) suggests   **************************
                                                      
                                                      If you believe that httpd should be allowed read access on the L directory by default.
                                                      Then you should report this as a bug.
                                                      You can generate a local policy module to allow this access.
                                                      Do
                                                      allow this access for now by executing:
                                                      # ausearch -c 'httpd' --raw | audit2allow -M my-httpd
                                                      # semodule -i my-httpd.pp
                                                      
4月 18 16:33:32 localhost.localdomain fprintd[32183]: No devices in use, exit

修复方法:

[User@Host ~]$ sudo setsebool -P httpd_use_fusefs 1
[User@Host ~]$ sudo systemctl restart httpd
posted @ 2020-10-29 15:25  Varden  阅读(3909)  评论(0编辑  收藏  举报