一.Apache
企业中常用的web服务,用于提供http://(超文本传输协议)
二.Apache的安装部署
yum install httpd -y ##apache软件
yum install httpd-manual ##apache的手册
systemctl start httpd
systemctl enable httpd
firewall-cmd --list-all
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
三.Apache的默认发布目录/文件
1.建立默认发布目录
/var/www/html ##apache的/目录
/var/www/html/index.html ##apache的默认发布目录
<h1>hello,world !</h1>
测试:在浏览器中搜索172.25.254.96
2.修改默认发布文件(http主配置文件 : /etc/httpd/conf/httpd.conf)
访问apache时没有指定文件名称时,默认访问配置文件中的默认访问文件(index.html),这个文件可以指定多个,有访问顺序。
vim /etc/httpd/conf/httpd.conf
<IfModule dir_module>
DirectoryIndex text.html index.html ##优先级text > index
</IfModule>
3.修改默认发布目录
mkdir /westos/html ##建立默认目录
vim /westos/html/westos.html#DocumentRoot "/var/www/html" ##注释默认目录
DocumentRoot "/westos/html" ##新默认发布目录
<Directory "/westos">
Require all granted
<Directory><IfModule dir_module>
DirectoryIndex index.html westos.html ##默认访问westos
</IfModule>
测试:172.25.254.116/ ##访问到/westos/html/westos.html 里的内容
4.修改默认端口
vim /etc/httpd/conf/httpd.conf
42 Listen 80 ##默认80 改为8080
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
测试:http://172.25.254.116:8080/
##可看到/var/www/html/index.html的内容
四、访问认证
1.设定其他用户的访问限制
只限制96主机不能访问
Order Allow,Deny ##优先级,谁在前,先读谁
Allow from all ##允许所有人访问
Deny from 172.25.254.16 ##禁止16主机访问
允许16主机访问 westos
禁止16主机访问westos
2.允许指定用户访问,且需要认证
生成认证文件 /etc/httpd/htuser
htpasswd -cm /etc/httpd/htuser admin1 ##-cm 新建
htpasswd -m /etc/httpd/htuser admin2
##注意添加用户时,只能用-m,否则会覆盖
AuthUserFile /etc/httpd/htuser ##读取的认证文件
AuthName "please input username and passwd" ##访问页面
AuthType basic ##基本的认证方式
Require valid-user tom ##只允许tom用户访问
Require valid-user ##允许文件里所有用户访问
五、Apache的虚拟主机设置
1.配置主机域名解析
vim /etc/hosts ##配置主机
172.25.254.116 www.westos.com news.westos.com music.westos.com
2.还原http的默认配置
3.建立虚拟主机的默认发布目录和文件
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
4.配置默认a_default.conf、music和news的文件
[root@localhost conf.d]# cat a_default.conf
<VirtualHost _default_:80>
DocumentRoot /var/www/html ##默认发布目录
CustomLog logs/default.log combined ##所有日志存放(访问,警告,拒绝,错误)
</VirtualHost>
5.网页访问结果查看
访问http://www.westos.com/结果:
访问http://www.news.com/结果:
访问http://www.music.com/结果:
六、https 与 http
1.https 访问时自动对数据加密,为了网络数据传输的安全
2.对https访问,需要安装mod_ssl,自动生成/
etc/httpd/conf.d/ssl.conf配置文件
若自己配置,需安装 crypto-utils
制作认证证书 genkey www.westos.com
3.修改配置文件 /etc/httpd/conf.d/ssl.conf,读取制作好的认证证书