阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

简单配置Squid代理和反向代理

113次阅读
没有评论

共计 2028 个字符,预计需要花费 6 分钟才能阅读完成。

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

Squid 的详细介绍:请点这里
Squid 的下载地址:请点这里

推荐阅读:

配置 Squid 代理 http 和 rsync http://www.linuxidc.com/Linux/2013-05/84642.htm

Squid:实现高速的 Web 访问 http://www.linuxidc.com/Linux/2013-04/83512.htm

CentOS 6.2 编译安装 Squid 配置反向代理服务器 http://www.linuxidc.com/Linux/2012-11/74529.htm

Squid 在企业网中的应用 http://www.linuxidc.com/Linux/2012-10/71818.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计2028字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中