squid2.6.之加速WEB支持虚拟主机配置(debian)

2.6相对2.5有了一些改变,大家可以去看 http://www.php-oa.com/2007/12/25/squid26peizhizuoweifanxiangdailideyanjiu.html

1.安装apt-get install squid

2.配置修改

cd /etc/squid
mv squid.conf squid.conf.bak
touch squid.conf

3.配置文件squid.conf内容如下

#服务器IP 192.168.1.161
#监听服务器的80端口,透明代理,支持域名和IP的虚拟主机
http_port 192.168.1.161:80  vhost

#单台使用,不使用该功能
icp_port 0
#限制同一IP客户端的最大连接数
acl OverConnLimit maxconn 16
http_access deny OverConnLimit
#防止被人利用为HTTP代理,设置允许访问的IP地址
acl myip dst 192.168.1.161
http_access deny !myip
#防止百度机器人爬死服务器
acl AntiBaidu req_header User-Agent Baiduspider
http_access deny AntiBaidu
#允许本地管理
acl Manager proto cache_object
acl Localhost src  192.168.1.161
http_access allow Manager Localhost
http_access deny Manager
#仅仅允许80端口的代理
acl Safe_ports port 80 # http
http_access deny !Safe_ports
acl all src 0.0.0.0/0.0.0.0
http_access allow all
#Squid信息设置
visible_hostname 192.168.1.161
cache_mgr webmaster@admin.com
#基本设置
cache_effective_user daemon
cache_effective_group daemon
tcp_recv_bufsize 65535 bytes
#2.6的反向代理加速配置
#代理到本机的80端口的服务,仅仅做为原始内容服务器
cache_peer 192.168.1.161 parent 8080 0 no-query originserver
#设置Squid所能使用的内存共64MB,这个值因人而异
cache_mem 64 MB
cache_swap_low 90
cache_swap_high 95
#最大缓存文件大小,超过这个值则不缓存,这个值因人而异
maximum_object_size 32768 KB
memory_pools_limit 100 MB
#装入内存缓存的文件大小
maximum_object_size_in_memory 256 KB
#磁盘缓存的类型和目录,大小,一二级目录的设置
cache_dir aufs /var/log/squid/cache 5512 64 256
#设置不想缓存的目录或者文件类型
acl QUERY urlpath_regex cgi-bin .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip .exe \?
cache deny QUERY
#打开emulate_httpd_log选项,将使Squid仿照Aapche的日志格式
emulate_httpd_log on
#日志格式combined的设置
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %{Host}>h %Ss:%Sh
#错误文档
#error_directory /var/log/squid/error
#这里是设置pid和日志文件的位置,因人而异,同时日志格式是combined
pid_filename /var/log/squid/squid.pid
cache_log /var/log/squid/cache.log
access_log /var/log/squid/access.log combined

logfile_rotate 4
cache_store_log none

hosts_file /etc/hosts
log_mime_hdrs off
strip_query_terms off


never_direct allow all
http_reply_access allow all
reload_into_ims on
redirect_rewrites_host_header off

##time out control
#connect_timeout 2 seconds
peer_connect_timeout 2 seconds
#read_timeout    2 seconds
#request_timeout 2 seconds
#persistent_request_timeout 10 seconds
client_lifetime 100 minutes
#half_closed_clients on
#pconn_timeout   10 seconds
collapsed_forwarding on
refresh_pattern -i .html 0 40% 60 ignore-reload
refresh_pattern -i .hml 0 40% 60 ignore-reload
refresh_pattern -i .gif 10 40% 60 ignore-reload
refresh_pattern -i .swf 10 40% 60 ignore-reload
refresh_pattern -i .jpg  10 40% 60 ignore-reload
refresh_pattern -i .js$ 10 40% 60 ignore-reload
refresh_pattern -i .css  10 40% 60 ignore-reload

4.创建目录

mkdir -p /var/log/squid/cache

5.测试:
/usr/local/squid/sbin/squid -z
/usr/local/squid/sbin/squid -NCd1
好了,现在访问你的服务器看看,已经好了。
为了测试是否可用,把http服务器给停了,你就可以看到squid2.6的信息了。

重新读取 squid.conf的方法: squid -k reconfigure
重启squid方法:/etc/init.d/squid restart

通过squidclient 查看squid2.6的信息

apt-get install squidclient

squidclient -h localhost -p 80 mgr:info|less

squid权威指南

上一篇: 让MYSQL支持全文索引   下一篇: Squid is already running!

提交疑问

回顶部