配置Squid代理和反向代理

r囧r小猫 2021-09-28 09:18 636阅读 0赞

配置Squid代理和反向代理

文章目录

  • 配置Squid代理和反向代理
  • 概念
  • 1.squid代理安装
  • 2.squid反向代理

概念

Squid cache(简称为Squid)是一个流行的自由软件,它符合GNU通用公共许可证。Squid作为网页服务器的前置cache服务器,可以代理用户向web服务器请求数据并进行缓存,也可以用在局域网中,使局域网用户通过代理上网。Squid主要设计用于在Linux一类系统运行。

1.squid代理安装

yum install squid #安装的是squid3.x版的

vi /etc/squid/squid.conf
添加如下(注意顺序,尽量排在顶端)
acl localnet src 192.168.1.0/32 #定义你的源本地网段或者IP
acl dst_net dst 8.8.8.8 www.linuxidc.com #定义代理可以访问的目标IP、域名、网段

http_access allow localnet #允许localnet 定义的源可以通过代理访问

http_access deny !dst_net #拒绝访问 不是dst_net定义的目标地址,即只能访问dst_net
#http_port =3128 默认监听端口3128 ,
#http_access默认拒绝所有,即没有匹配到任何一项,就拒绝
然后在你的客户IE设置代理IP和端口,如下图:

xxxxxx

2.squid反向代理

vi /etc/squid/squid.conf

添加acl和http_access 允许所有访问

在http_port=80 设置监听端口80,然后在下面添加

cache_peer 192.168.1.156 parent 8000 0 name=a #设置多个后台IP和端口,另加一行

cache_peer_domain a www.linuxidc.com #多个域名空格隔开
出现下面错误:

ERROR

The requested URL could not be retrieved


The following error was encountered while trying to retrieve the URL: /

Invalid URL

Some aspect of the requested URL is incorrect.

Some possible problems are:

Missing or incorrect access protocol (should be “http://” or similar)

Missing hostname

Illegal double-escape in the URL-Path

Illegal character in hostname; underscores are not allowed.

Your cache administrator is root.

出现上面的错误,需要修改下:

http_port 80 defaultsite=www.linuxidc.com

cache_peer 192.168.1.156 parent 8000 0 no-query originserver weight=1 name=a

cache_peer_domain a www.linuxidc.com

或者:(推荐)

http_port 80 transparent

cache_peer 192.168.1.156 parent 8000 0 no-query originserver name=a

cache_peer 192.168.1.144 parent 80 0 no-query originserver name=b

cache_peer_domain a www.linuxidc.com

cache_peer_domain b www.linuxidc.net

然后重新访问正常

2.反向代理
Access Denied Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect.
这样的错误,需要在客户端取消代理,即:不使用任何代理,解决。

发表评论

表情:
评论列表 (有 0 条评论,636人围观)

还没有评论,来说两句吧...

相关阅读

    相关 squid反向代理

    一.反向代理的概念   什么是反向代理呢?其实,反向代理也就是通常所说的WEB服务器加速,它是一种通过在繁忙的WEB服务器和Internet之间增加一个高速的 WE

    相关 squid反向代理的原理

    代理服务器是使用非常普遍的一种将局域网主机联入互联网的一种方式,使用代理上网可以节约紧缺的IP地址资源,而且可以阻断外部主机对内部主机的访问,使内部网主机免受外部网主机的攻击。