toxic

备忘录

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

首先介绍下代理的几种方式

1.普通代理:需要客户机在浏览器中设定代理服务器的地址和端口。

2.透明代理:适用于企业网关主机,客户机不需要指定代理服务器地址端口等信息,通过iptables将客户机的web访问数据交给代理服务程序处理。

3.反向代理:外部用户通过代理服务器来访问公司内部数据。

 

squid的安装

yum -y install squid*

【默认安装的配置文件地址在/etc/squid/squid.conf】
【squid命令】
service squid start/restart/stop 【启动服务】
squid -k reconfig 【重新加载配置文件】

在配置之前 首先要了解一下 ACL访问控制

定义ACL列表
acl 列表名 列表类型 列表内容
例子:acl all src 192.168.10.0/24

定义acl动作
http_access deny/allow 列表名
例子: http_access allow all

列表类型
src  源ip
dst 目的ip
port 端口
srcdomain 源域名
dstdomain 目的域名
time 时间
maxconn 最大连接数
url_regex url正则过滤
urlpath_regex urlpath正则过滤

 

 

1.普通代理配置

假设squid服务器的ip为 192.168.10.1
做测试请先清空squid.conf文件内容

vi /etc/squid/squid.conf

在squid.conf中加入

http_port 192.168.10.1:3128
visible_hostname 192.168.10.1
acl innet src 192.168.10.0/24
acl all src 0.0.0.0/0.0.0.0
http_access allow innet
http_access deny all

 

 

2.透明代理配置

1.修改squid.conf的 http_port为

http_port 192.168.10.1:3128 transparent

2.重新加载配置文件

squid -k reconfig

3.添加iptables规则把全部的内部http请求重定向到3128端口

iptables -t nat -I PREROUTING -i eth0 -s 192.168.10.0/24 -p tcp --dport 80 -j REDIRECT --to 3128

 

3.反向代理

修改squid.conf为

http_port 200.168.10.1:80 vhost
visible_hostname 200.168.10.1
acl all src 0.0.0.0/0.0.0.0
http_access allow all
cache_peer 192.168.10.2 parent 80 0 originserver

如果是反向代理需要配置虚拟主机(同ip同端口不同域名)映射则代码为
http_port 200.168.10.1:80 vhost
acl all src 0.0.0.0/0.0.0.0
cache_peer 192.168.10.2 parent 80 0 originserver name = a 
cache_peer 192.168.10.2 parent 80 0 originserver name = b
cache_peer_domain a www.lamp.com
cache_peer_domain b www.baidu.com
cache_peer_access a allow all
cache_peer_access b allow all

 

 

 

 

 

posted on 2012-08-13 19:46  toxic  阅读(224)  评论(0编辑  收藏  举报