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