index.html 文件是你使用域名访问网站而不是访问特定网页时的默认文件。在 /var/www/html 中,创建一个名字为 index.html 的文件,在其中添加字符串 Hello World 。你不需要添加任何的 HTML 标志去完成这项工作。web 服务器的唯一任务是提供文本数据流,服务器不知道数据是什么,也不知道如何呈现它。它只是将数据流传输给请求主机。
保存文件后,将所有权设置为 apache.apache 。
chown apache.apache index.html
4. 启动 Apache
复制代码
$ sudo systemctl start httpd
$ systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since 一 2018-04-16 11:01:59 CST; 5h 50min ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 41464 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
Main PID: 41473 (httpd)
Status: "Total requests: 6; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─41473 /usr/sbin/httpd -DFOREGROUND
├─41474 /usr/sbin/httpd -DFOREGROUND
├─41475 /usr/sbin/httpd -DFOREGROUND
├─41476 /usr/sbin/httpd -DFOREGROUND
├─41477 /usr/sbin/httpd -DFOREGROUND
├─41478 /usr/sbin/httpd -DFOREGROUND
└─43670 /usr/sbin/httpd -DFOREGROUND
4月 16 11:01:58 Sun systemd[1]: Starting The Apache HTTP Server...
4月 16 11:01:59 Sun httpd[41473]: AH00557: httpd: apr_sockaddr_info_get() failed for Sun
4月 16 11:01:59 Sun httpd[41473]: AH00558: httpd: Could not reliably determine the s...age
4月 16 11:01:59 Sun systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
复制代码
[User@Host ~]$ cat /etc/httpd/conf.d/welcome.conf
#
# This configuration file enables the default "Welcome" page if there
# is no default index page present for the root URL. To disable the
# Welcome page, comment out all the lines below.
#
# NOTE: if this file is removed, it will be restored on upgrades.
#
<LocationMatch "^/+$">
Options +Indexes
ErrorDocument 403 /.noindex.html
</LocationMatch>
<Directory /usr/share/httpd/noindex>
AllowOverride None
Require all granted
</Directory>
Alias /.noindex.html /usr/share/httpd/noindex/index.html
Alias /noindex/css/bootstrap.min.css /usr/share/httpd/noindex/css/bootstrap.min.css
Alias /noindex/css/open-sans.css /usr/share/httpd/noindex/css/open-sans.css
Alias /images/apache_pb.gif /usr/share/httpd/noindex/images/apache_pb.gif
Alias /images/poweredby.png /usr/share/httpd/noindex/images/poweredby.png
复制代码
解释一下,"default index page“ 指的是位于http文件服务器下载目录的文档 index.html。
[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.
...
复制代码
(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>
...
复制代码
(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
#
...
复制代码
[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.
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
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