1.Apache的作用
在web被访问时通常使用http://的方式
http:// ##超文本传输协议http:// 超文本传输协议提供软件:
Apache
nginx
stgw
jfe
Tengine
2.Apache的安装
dnf install httpd.x86_64 -y
3.Apache的启用
systemctl enable --now httpd ##开启服务并设定服务位开机启动
firewall-cmd --list-all ##查看火墙信息
firewall-cmd --permanent --add-service=http ##在火墙中永久开启http访问
firewall-cmd --permanent --add-service=https ##在火墙中永久开启https访问
firewall-cmd --reload ##刷新火墙使设定生效
4.Apache的基本信息
服务名称: httpd
配置文件:
/etc/httpd/conf/httpd.conf ##主配置文件
/etc/httpd/conf.d/*.conf ##子配置文件
默认发布目录: /var/www/html
默认发布文件: index.html
默认端口: 80 #http
443 #https
用户: apache
日志: /etc/httpd/logs
5.Apache的基本配置
#1.Apache端口修改#
vim /etc/httpd/conf/httpd.conf
Listen 8080
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
systemctl restart httpd
http://172.25.254.100:8080
2.默认发布文件
vim /etc/httpd/conf/httpd.conf
DirectoryIndex westos.html index.html
systemctl restart httpd
3.默认发布目录
mkdir /var/www/westos
mv /var/www/westos /var
vim /etc/httpd/conf/httpd.conf
DocumentRoot "/var/westos"
<Directory "/var/westos">
Require all granted
</Directory>
systemctl restart httpd
firefox http://192.168.0.11
6.Apache的访问控制
######squit 正向代理#########
实验环境:
单网卡主机设定ip不能上网
双网卡主机设定ip1可以连接单网卡主机,设定ip2可以上网
实验效果:
让单网卡主机不能上网但浏览器可以访问互联网页面
实验环境
建立虚拟机westosb为代理机:
hostnamectl set-hostname squid.westos.org
vim /etc/sysconfig/network-scripts/ifcfg-ens3
DEVICE=ens3
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.217
PREFIX=24
GATEWAY=172.25.254.250
DNS1=114.114.114.114
nmcli connection reload
nmcli connection show
真机连接代理机:
dnf install squid -y
vim /etc/squid/squid.conf
59 http_access allow all
65 #去掉
6 systemctl restart squid
8 netstat -antlupe | grep squid
10 firewall-cmd --permanent --add-service=squid
11 firewall-cmd --reload
12 firewall-cmd --list-all
13 ping www.baidu.com
建立虚拟机westosaaaa:
hostnamectl set-hostname westosaaaa.westos.org
vim /etc/sysconfig/network-scripts/ifcfg-ens3
DEVICE=ens3
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.117
PREFIX=24
nmcli connection reload
nmcli connection show
真机连接虚拟机:
dnf install firefox -y
进入网页进行设置即可上网
#####squid反向代理###
在服务器westosaaaa中:
4 dnf install httpd -y ##下载httpd服务器
6 systemctl enable --now httpd
7 firewall-cmd --permanent --add-service=http
9 firewall-cmd --reload
10 ip a
11 echo 172.25.254.117 > /var/www/html/index.html
在代理机squid中:
16 less /usr/share/doc/squid/squid.conf.documented
17 vim /etc/squid/squid.conf ##编辑端口
62 http_port 80 vhost vport #vhost 支持虚拟域名 vport 支持虚拟端口
63 cache_peer 172.25.254.117 parent 80 0 proxy-only ##编辑改为服务器端口,即可使用
18 systemctl restart squid
19 systemctl status squid
20 rpm -qa | grep httpd
21 firewall-cmd --list-all
22 firewall-cmd --permanent --add-service=http
23 firewall-cmd --reload
访问217看到的是172.25.254.117上的数据