1.Apache的基本信息
??? Apache:对外提供超文本传输协议的一种软件 ??? 超文本传输协议:提供网络资源的共享 在web被访问时通常使用http://的方式 ??? http:// ##超文本传输协议 ??? http:// 超文本传输协议 ??? 提供软件:Apache,nginx,stgw,jfe,Tengine ??? curl -I 网站 ??? #可以查看被访问网站是由什么软件提供的超文本传输协议
??? 服务名称:httpd ??? 配置文件: ??? /etc/httpd/conf/httpd.conf ##主配置文件 ??? /etc/httpd/conf.d/*.conf ##子配置文件 ??? 默认发布目录:/var/www/html ??? 默认发布文件:index.html ??? 默认端口:80 #http ??? 443 #https ??? 用户:apache ??? 日志:/etc/httpd/logs
2.Apache的安装
dnf install httpd -y
systemctl enable --now httpd
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
将两个服务加入火墙
firewall-cmd --reload

?3.修改测试页内容

vim /var/www/html/index.html

?结果

3.Apache的基本配置
1.更改Apache端口
vim /etc/httpd/conf/httpd.conf

systemctl restart httpd
netstat -antlupe |grep httpd查看端口

?2.默认发布文件的管理
cd /var/www/html/
[root@westoslinux html]# ls
index.html
vim cui.html

vim /etc/httpd/conf/httpd.conf
167行
systemctl restart httpd

优先访问cui
想要访问index要输入完整目录


3.默认发布目录的管理?
mkdir /westos_apache
ls
cd westos_apache/
vim index.html
建立新目录

修改配置文件
vim /etc/httpd/conf/httpd.conf
DocumentRoot "/westos_apache"
<Directory "/westos_apache">
# Allow open access:
Require all granted
</Directory>


semanage fcontext -a -t httpd_sys_content_t '/westos_apache(/.*)?'
将文件类型改为apache识别的类型
restorecon -RF /westos_apache/
systemctl restart httpd
效果测试:

4.Apache的访问控制
在html下建立westos目录
vim /etc/httpd/conf/httpd.conf
122行
DocumentRoot "/var/www/html"
<Directory "/var/www/html/westos">
Order Allow,Deny
Allow from all
Deny from 172.25.254.12
</Directory>
?Allow和Deny的读取顺序: 允许任何人访问 不允许172。25。254。12访问 ##因为先读Allow后读Deny那么Deny里面的信息会覆盖Allow中的信息
(1)黑名单

?效果测试:真机无法访问

?(2)白名单
vim /etc/httpd/conf/httpd.conf
systemctl restart httpd

?查看效果

?5.基于用户的访问方式
? 1.? 建立apache的目录认证文件
实验材料准备:
cd /var/www/html htpasswd -cm /etc/httpd/.htpasswd admin ##当认证文件不存在时,需要加-c参数 htpasswd -m /etc/httpd/.htpasswd lee ##当认证文件存在时,加-c参数会删除原有内容 cat /etc/httpd/.htpasswd ##查看用户认证文件

?2.配置文件修改
基本认证 只有admin用户可以通过认证 所有用户可以通过认证 <Directory "/var/www/html/yitian”> AuthUserFile /etc/httpd/.htpasswd??? ##指定认证文件 AuthName “Please input username and passwd” ##指定认证提示 AuthType basic? ##指定认证类型 1.? # Require user admin? ##指定认证用户 ##认证文件中admin用户可以通过认证 2.? Require valid-user?? ##认证文件中的所有用户都可以通过认证 ##两个参数指定写一个就好
?情况一:

?效果测试


?情况二:

?效果测试:


?6.Apache的虚拟主机
1.实验素材

?配置文件内容: 写完了重启服务
<VirtualHost _default_:80>
DocumentRoot "/var/www/html"
Customlog logs/default.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName wenku.westos.org
DocumentRoot "/var/www/vhost/wenku"
Customlog logs/wenku.log combined
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/vhost/news"
Customlog logs/news.log combined
</VirtualHost>

?域名解析:浏览器所在主机中操作
172.25.254.112 news.westos.org wenku.westos.org
?

?效果测试:



七、Apache的语言支持:
PHP语言 安装php,添加php发布文件内容如下,重启服务即可访问:
 cgi语言 安装cgi语言的解释器: 创建cgi的发布目录
 更改cgi的发布文件:
 在http.conf中,定义的pl运行位置是/var/www/cgi-bin/,而现在,运行的位置变化了,需要重新说明:
 访问一下:

?
?
?
?
#squid正向代理
1.能上网的主机是代理
代理的操作
vim /etc/sysconfig/network-scripts/ifcfg-ens3
DEVICE=ens3 ONBOOT=yes BOOTPROTO=none IPADDR=172.25.254.112 PREFIX=24 GATEWAY=172.25.254.250 DNS1=114.114.114.114 ???????????????? 重新加载网络
dnf install squid -y
vim /etc/squid/squid.conf
?59\65行修改

systemctl restart squid
48 firewall-cmd --permanent --add-port=3128
49 firewall-cmd --permanent --add-port=3128/tcp
50 firewall-cmd --reload
客户端:
直接在浏览器修改
references? >?? network settings? >?

效果测试:客户端ping不通baidu,但是浏览器可以用

?#squid反向代理
原理:把westosb作为代理,westosa是主服务器,用户访问westosa时,显示的是westob中的内容
1.代理端:
dnf install httpd.x86_64 -y ?? 48? echo 172.25.254.212 > /var/www/html/index.html ?? 52? systemctl stop --now firewalld.service ?? 54? systemctl enable --now httpd

?2.主服务器:修改配置文件
vim /etc/squid/squid.conf
修改好后 systemctl? restart? squid
http_port 80 vhost vport
cache_peer 172.25.254.212 parent 80 0 proxy-only

?效果查看:

systemctl disable --now squid
服务关闭后网页消失
|