1. 基于版本 2.6 stable18
2. apache 缓存代理配置。 注:apache 端口82
3. 运行
1) 建立cache目录结构 squid -z
2)启动 squid -D -sYC
4. 参考资料:
1) Squid中文权威指南 http://blog.chinaunix.net/u2/71313/showart_1006122.html
2) (很全面细致,值得参考)squid2.6加速WEB支持虚拟主机配置心得体会, http://www.chinaunix.net/jh/38/873126.html
5. 常见问题
1) 如果出现以下问题
[quote] * Invalid Request
Some aspect of the HTTP Request is invalid. Possible problems:
* Missing or unknown request method
* Missing URL
* Missing HTTP Identifier (HTTP/1.0)
* Request is too large
* Content-Length missing for POST or PUT requests
* Illegal character in hostname; underscores are not allowed [/quote]
应该启用 vhost,配置例如:
[quote] http_port 3128 vhost vport [/quote]
并且在 所有 http_access 配置前增加
[quote]http_access allow all[/quote]
以便让对squid发起的请求能够顺利通过。
修改配置后,可以执行下面的命令,快速生效:
[quote]squid -n Squid -k reconfigure[/quote]
2. apache 缓存代理配置。 注:apache 端口82
visible_hostname raymond-linux
# cache服务器的名称
# 缓存管理员
cache_mgr webmaster@example.com
# 如果不能访问,需要 http_access deny !Safe_ports 改为allow或将 3128加入 safe_ports
# 也可配置监听80端口,并配置为加速模式
http_port 3128 vhost vport
# cache服务器之间通信的端口UDP
icp_port 3130
# 当然cache_peer还可以设置兄弟节点、上级cache服务器等等,这里这设置了源服务器地址
# 设置上级根服务器的地址,也就是电信源服务器地址
cache_peer 172.20.35.251 parent 82 0 no-query originserver name=myAccel
# cache目录和大小的设置,1GB硬盘空间和256M内存
#前面已经设置 cache _dir /var/spool/squid
#cache_dir ufs /usr/squid/var/cache 256 16 256
cache_mem 16 MB
cache_peer_access myAccel allow all
#最大缓存文件大小,超过这个值则不缓存,这个值因人而异
cache_swap_low 90
cache_swap_high 95
maximum_object_size 20000 KB
#装入内存缓存的文件大小,这个值对Squid的性能影响比较大,因为默认值是8K,超过8K的文件都不装入内存,而实际应用中很多网页和图片等都超过8KB, 个人认为如果缓存不装入内存而存在磁盘上,性能和apache直接读取磁盘文件没什么区别,甚至不如直接访问apache,现在设置成小于4兆的文件通通装入内存缓存.
maximum_object_size_in_memory 4096 KB
# 主机文件路径
hosts_file /etc/hosts
# 设置日志目录和日志格式#squid
pid_filename /var/log/squid/squid.pid
#已在前面配置 access_log /var/log/squid/access.log squid
#已在前面配置 cache_log /var/log/squid/cache.log
#已在前面配置 cache_store_log /var/log/squid/store.log
#模拟apache 日志格式
emulate_httpd_log on
#设置不想缓存的目录或者文件类型,动态文件,大文件不缓存。不过一般最好缓存
#已在前面配置 acl all src 0.0.0.0/0.0.0.0
acl QUERY urlpath_regex cgi-bin .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip .exe
cache deny QUERY
# 允许所有用户访问 , 要打开
http_access allow all
#apache ip
acl apache_server dst 127.0.0.1
http_access allow apache_server
#正向代理,这里不需要
#acl our_sites dstdomain sohu.com
#http_access allow our_sites
3. 运行
1) 建立cache目录结构 squid -z
2)启动 squid -D -sYC
4. 参考资料:
1) Squid中文权威指南 http://blog.chinaunix.net/u2/71313/showart_1006122.html
2) (很全面细致,值得参考)squid2.6加速WEB支持虚拟主机配置心得体会, http://www.chinaunix.net/jh/38/873126.html
5. 常见问题
1) 如果出现以下问题
[quote] * Invalid Request
Some aspect of the HTTP Request is invalid. Possible problems:
* Missing or unknown request method
* Missing URL
* Missing HTTP Identifier (HTTP/1.0)
* Request is too large
* Content-Length missing for POST or PUT requests
* Illegal character in hostname; underscores are not allowed [/quote]
应该启用 vhost,配置例如:
[quote] http_port 3128 vhost vport [/quote]
并且在 所有 http_access 配置前增加
[quote]http_access allow all[/quote]
以便让对squid发起的请求能够顺利通过。
修改配置后,可以执行下面的命令,快速生效:
[quote]squid -n Squid -k reconfigure[/quote]