配置Squid代理和反向代理

配置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.
这样的错误,需要在客户端取消代理,即:不使用任何代理,解决。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值