squid apache 缓存代理配置

1. 基于版本 2.6 stable18

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]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值