squid+apache正反向代理服务

           Squid cache(简称为Squid)是一个流行的自由软件(GNU通用公共许可证)的代理服务器和Web缓存服务器。Squid有广泛的用途,从作为网页服务器的前置cache服务器缓存相关请求来提高Web服务器的速度,到为一组人共享网络资源而缓存万维网,域名系统和其他网络搜索,到通过过滤流量帮助网络安全,到局域网通过代理上网。Squid主要设计用于在Unix一类系统运行。

squid正向代理

在代理机:

hostnamectl set-hostname squid.westos.org     ##修改主机名
vim /etc/sysconfig/network-scripts/ifcfg-ens3   ##编写网卡配置文件
//编写内容
DEVICE=ens3
ONBOOT=yes
NAME=westos
BOOTPROTO=none
IPADDR=172.25.254.111    ##ip
PREFIX=24     ##子网掩码
GATEWAY=172.25.254.250   ##网关
DNS1=114.114.114.114
//
nmcli connection show 
nmcli connection delete Wired\ connection\ 1   ##删除多余的网卡
nmcli connection reload 
nmcli connection up westos
ifconfig   ##查看
route -n  ##查看网关设置
ping www.baidu.com   ##可以ping通
dnf install squid -y    ##下载代理软件
vim /etc/squid/squid.conf
//编写内容
 59 http_access allow all    ##允许所有网络请求
 60 
 61 # Squid normally listens to port 3128
 62 http_port 3128
 63 
 64 # Uncomment and adjust the following to add a disk cache directory.
 65 cache_dir ufs /var/spool/squid 100 16 256   ##删掉注释
 66 
 67 # Leave coredumps in the first cache dir
 68 coredump_dir /var/spool/squid
//
14  systemctl enable --now squid.service   ##开启代理服务
   15  firewall-cmd --permanent --add-service=squid    ##在系统防火墙中永久开启squid服务
   16  firewall-cmd --reload   ##刷新防火墙
   
   18  systemctl restart squid.service 

 在测试机:

dnf install firefox -y      ##下载测试浏览器
nm-connection-editor      ##图形方法设置网卡

手动删除原始网卡,添加新网卡,新网卡设置如下图:

  在测试机的firefox上输入网址www.baidu.com进不去

在网页最右边 三条横线---->preferences----->setting(最底下)
修改connection settings为下图

 再次刷新可以进入百度网页。

squid反向代理

代理机(172.25.254.211):

 8  vim /etc/squid/squid.conf   ##编写代理服务的配置文件
//
 62 http_port 80 vhost vport   ##如果通过http服务访问总部代理机,将其作为代理跳板,通过80端口去访问有apache服务的总部机
 63 cache_peer 172.25.254.111 parent 80 0 proxy-only  ##172.25.254.111为父级服务器,从80端口缓存数据,0表示无备份主机,proxy-only表示只是作为代理服务器
//   
    9  systemctl  restart squid.service   ##重启squid服务
   10  firewall-cmd --permanent --add-service=http   ####在系统防火墙中永久开启squid服务
   11  firewall-cmd --reload ##刷新防火墙

测试机(172.25.254.111):

    9  dnf install httpd -y
   10  systemctl enable --now httpd
   
   12  systemctl start firewalld
  
   14  firewall-cmd --permanent  --add-service=http
   15  firewall-cmd --reload 
   16  echo 172.25.254.111 > /var/www/html/index.html

在真实主机上测试,输入172.25.254.211,显示的是总服务机172.25.254.111/var/www/html/index.html中的内容“172.25.254.111",如图所示:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值