简单的反向代理设置,Squid来设置正向代理还是不是很难的
1、cache_peer来指定所需要代理的服务器的IP
2、squid 2.7中all已经被默认定义
3、cache_peer 192.168.1.50 parent 81 0 no-query originserver weight=1 name=a
cache_peer_domain a www.serverA.com
#上面表示
#从客户端过来的请求,如果是 www.serverA.com,则Squid向 Server 192.168.1.50的端口81发送请求;
#name=a表示给cache_peer一个别名
4、cache_peer_access a allow all
(1)命令cache_peer的定义格式是:
cache_peer hostname type 3128 3130
hostname 是用来指定获取缓冲的PROXY主机的名字
type 是PROXY主机的类型,有以上PARENT SIBLING两种
3128:HTTP_PORT
3130:ICP_PORT
(2)附加配置选项(注意应为小写,配置时)
NO-QUERY:不做查询操作,直接获取数据
NO-NETDB-EXCHANGE:代理服务器之间不交互信息
NO-DIGEST:代理服务器之间不做摘要表查询,直接用ICP协议沟通(同级代理)
PROXY-ONLY:直接获取对方缓冲,转交给代理服务器的客户端,而不存入本地
ROUND-ROBIN:如果设置数部上层服务器,那么轮流查询父级服务器
LOGIN=USER:PASSWD:要求对方做帐号及密码验证,例如
cache_peer 192.168.1.41 sibling 3128 3130 login=kao:123456
#
# Recommended minimum configuration:
#
visible_hostname www.zzy.com
#经测试,上面的名字可加可不加,但是别的博文里有说不加就无法运行了,所以建议还是加以下吧
#猜测:visible_hostname可能在有多个squid的代理服务器的情况下才能发挥作用
# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
#下面是设定acl访问控制列表,其实下面的内容就跟定义变量一样
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
#acl Safe_ports port 8181 #add by zzy
acl CONNECT method CONNECT
#zzy write on 15:01
#正向代理时,测试用的,经此处测试,猜测应该按照顺序匹配访问列表,一旦有匹配上的,才会退出。
#至于匹配上了,就是符合这边的条件了,即你访问的端口如果是8181,那么在下一条被注释的语句就匹配上了
#acl specify_port port 8181
#http_access deny localhost
#http_access deny specify_port
#name一般在有多个要反向代理的服务器时才需要,不过最好还是要了吧
#不知道他能不能有多个IP对应同一个name 有待测试
cache_peer 220.181.111.147 parent 80 0 no-query originserver name=baidu
cache_peer 192.168.2.125 parent 8080 0 no-query originserver name=local_zzy
#cache_per_domain 就是客户端访问squid服务器时所用的域名咯,你要是之前有接触过Nginx的反向代理服务器,对这个就非常有感觉了。
cache_peer_domain baidu www.baidu.com
cache_peer_domain local_zzy www.zzyl.com
#下面这条语句就没有测试过了,作用应该是给每一个后端的服务器设定相应的各自的访问控制列表吧,有待进一步研究。
#cache_peer_access baidu allow all
#
# Recommended minimum Access Permission configuration:
#
# Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager
# Deny requests to certain unsafe ports
http_access deny !Safe_ports
# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports
# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost
#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#
# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet
http_access allow localhost
# And finally deny all other access to this proxy
#http_access deny all
http_access allow all
# Squid normally listens to port 3128
#这个语句的accel貌似很重要,网上是这么说的:
#设定squid为accel加速模式,vhost必须要加.否则将无法将主机头转发至后端服务器,访问时就会出现无法找到主机头的错误.
#我之前尝试很多种方式都没有成功,不过加了这个accel之后的内容,第一次就成功了。
http_port 192.168.2.125:80 accel vhost vport
# Uncomment and adjust the following to add a disk cache directory.
#cache_dir ufs /opt/squid/var/cache/squid 100 16 256
# Leave coredumps in the first cache dir
coredump_dir /opt/squid/var/cache/squid
# Add any of your own refresh_pattern entries above these.
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320