一、Apache 默认发布目录/文件
1.配置yum源,安装http服务
2.打开http,修改防火墙配置
systemctl start httpd
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
3.建立默认发布文件 /var/www/html/index.html
<h1>hello everyone</h1> ##h1字体设置
网页访问,可看到默认发布文件的内容
4.修改默认发布文件(http 主配置文件:/etc/httpd/conf/httpd.conf)
167 <IfModule dir_module>
168 DirectoryIndex test.html index.html ##优先级,谁在前先读谁,不存在的话就跳过
169 </IfModule>
5.重启http服务,网页访问将看到test.html 的内容:
6.修改默认发布目录
mkdir /hello/html -p
修改主配置文件 /etc/httpd/conf/httpd.conf
重启httpd服务,网页访问将看到/hello/html/index.html内容
#####注意selinux级别#####
当selinux=disabled,重启http服务后可看到默认发布文件
但是,当selinux=enforing,必须修改安全上下文才能看到默认发布文件
semanage fcontext -a -t httpd_sys_content_t '/hello(/.*)?'
restorecon -RvvF /hello/
########################
二、Apache的虚拟主机设置
1.还原http的默认配置
2.建立虚拟主机的默认发布目录和文件
mkdir /var/www/virtual/news/html -p
mkdir /var/www/virtual/music/html -p
vim /var/www/virtual/music/html/index.html
vim /var/www/virtual/news/html/index.html
3.配置默认、music和news的文件 ##目录/etc/httpd/conf.d/
[root@testdb conf.d]# cat default.conf
<VirtualHost _default_:80>
DocumentRoot /var/www/html ##默认发布目录
CustomLog logs/default.log combined ##所有日志存放(访问,警告,拒绝,错误)
</VirtualHost>
4.重启http服务,在访问主机进行域名解析(/etc/hosts)
5.网页访问结果查看
访问http://www.westos.com/结果: