`
tianyihuyidao9
  • 浏览: 159087 次
  • 性别: Icon_minigender_1
  • 来自: 济南
文章分类
社区版块
存档分类
最新评论

squid配置反向代理

 
阅读更多
[size=large]通过采用Squid的反向代理功能提高客户端对网站的浏览速度;
测试环境:
           普通PC机+RedHat linux As4+Squid 2.6
技术概述:
以下分别采用了3种不同的模式在测试平台下对网站进行加速,原理:用户请求-〉DNS解析到Squid-Cache-〉Squid-Cache通过本地hosts进行解析-〉Web服务器(如果没有缓存)-〉Squid-Cache服务器-〉用户。 详细配置文档如下:

一、    Squid网路拓扑

二、    配置步骤
说明:粉红色标注是运行命令,红色标注关键的参数,蓝色标注是配置文件的代码;
Setp 1 – Download file and compiling Squid
1.    首先卸载自带的squid程序,使用命令如下   
       #rpm –q squid           #检测是否已安装了squid
# rpm –e squid全文件名  #卸载系统自带已安装上的squid
  2.下载最新稳定版squid以及编译安装
     Address: http://www.squid-cache.org/
          # tar zxvf squid-2.6.STABLE16.tar.gz
          # cd squid-2.6.STABLE16
# vi config.sh  #新建此配置文件
代码如下:
引用

#!/bin/bash
SQUID_ROOT="/Data/apps/squid"
./configure --prefix=$SQUID_ROOT \
--enable-useragent-log \
--enable-referer-log \
--enable-default-err-language=Simplify_Chinese \
--enable-err-languages="Simplify_Chinese English" \
--disable-internal-dns   #停止本地的dns解析       
         # sh config.sh
         # make
         # make install

Setp 2 – Basic Configuration
引用

         # cd /Data/apps/squid/
         # mkdir cache
         # chown squid.squid *
         # chmod 777 -R var  #目的是为了增加日志文件的写入权限

Setp 3 –Particular Configuration
引用


# cd /Data/apps/squid/etc
# mv squid.conf squid.conf.bak #备份原文件
# vi squid.conf #新建文件

A. 模式1:Squid对应多台web服务器
A1。在vi /etc/hosts中:加入内部的DNS解析,比如:
引用

192.168.0.1     www.pig2pig.com
192.168.0.2     bbs.pig2pig.com


A2。#vi /Data/apps/squid/etc/squid.conf
代码如下:
引用

# visible name
visible_hostname cache.pig2pig.com
# cache config: space use 1G and memory use 256M
   cache_dir ufs /Data/apps/squid/cache 1024 16 256
   cache_mem 256 MB
   cache_effective_user squid  #设置运行时的用户和组权限
cache_effective_group squid
         # 反向加速配置
http_port 80   # squid监听的端口,客户访问网站的端口
httpd_accel_host virtual  # WEB服务器的IP地址,此模式下设置为:virtual
httpd_accel_single_host off  # 设置on时缓冲请求到单台Server,off对应virtual
httpd_accel_port 80    # WEB服务器的端口(对于多台web服务器,端口必须一致)
httpd_accel_uses_host_header on  # 完成多个WEB服务器的反向代理功能
httpd_accel_with_proxy off    # 停用代理本地上网
# accelerater my domain only
acl acceleratedHostA dstdomain  www.pig2pig.com
acl acceleratedHostB dstdomain  bbs.pig2pig.com
# accelerater http protocol on port 80
acl acceleratedProtocol protocol HTTP
acl acceleratedPort port 80
# access arc
acl all src 0.0.0.0/0.0.0.0
# Allow requests when they are to the accelerated machine
AND to the right port with right protocol
http_access allow acceleratedProtocol acceleratedPort
acceleratedHostA
http_access allow acceleratedProtocol acceleratedPort
acceleratedHostB
http_access allow all
# logging
emulate_httpd_log on
cache_store_log none
# manager
acl manager proto cache_object
http_access allow manager all
cachemgr_passwd pass all
cache_mgr admin@pig2pig.com
#swap 性能微调
half_closed_clients off
cache_swap_high 100%
cache_swap_low 95%
maximum_object_size 1024 KB
# 控制对象的超时时间 (S_Data-Data)refresh_pattern -i .html 60 90% 10080 reload-into-ims
#refresh_pattern -i \.html$ 60 90% 10080 reload-into-ims
refresh_pattern -i .png 60 90% 10080 reload-into-ims
refresh_pattern -i .jpg 1440 90% 129600 reload-into-ims
refresh_pattern -i .gif 1440 90% 129600 reload-into-ims
refresh_pattern -i .js 1440 90% 10080 reload-into-ims
refresh_pattern -i .swf 1440 90% 129600 reload-into-ims
refresh_pattern -i .bmp 1440 90% 129600 reload-into-ims
# refresh_pattern -i .shtml 1440 90% 129600 reload-into-ims
# refresh_pattern -i .hml 1440 90% 129600 reload-into-ims
# 禁止缓存
hierarchy_stoplist cgi-bin ?
hierarchy_stoplist -i ^https:\\ ?
acl QUERY urlpath_regex -i cgi-bin \? \.php \.xml
acl denyssl urlpath_regex -i ^https:\\
no_cache deny QUERY
no_cache deny denyssl
#logfile_rotate 可以用logfile_rotate 0来取消自动操作
logfile_rotate 4



B.模式2:Squid 与 web是单独两台服务器
# vi /Data/apps/squid/etc/squid.conf  代码如下:
引用

# visible name
visible_hostname cache.pig2pig.com
# cache config: space use 1G and memory use 256M
   cache_dir ufs /Data/apps/squid/cache 1024 16 256
   cache_mem 256 MB
   cache_effective_user squid  #设置运行时的用户和组权限
cache_effective_group squid
         # 反向加速配置
http_port 80   # squid监听的端口,客户访问网站的端口
httpd_accel_host ip_address  # WEB服务器的IP地址
httpd_accel_single_host on # 设置转发为缓冲的请求到一台单独的机器
httpd_accel_port 80    # WEB服务器的端口
httpd_accel_uses_host_header off  # 完成单台WEB服务器的反向代理功能
httpd_accel_with_proxy off    # 停用代理本地上网
# accelerater my domain only
acl acceleratedHostA dst ip_address # WEB服务器的IP地址
# accelerater http protocol on port 80
acl acceleratedProtocol protocol HTTP
acl acceleratedPort port 80
# access arc
acl all src 0.0.0.0/0.0.0.0
# Allow requests when they are to the accelerated machine
AND to the right port with right protocol
http_access allow acceleratedProtocol acceleratedPort
acceleratedHostA
http_access allow all
# logging
emulate_httpd_log on
cache_store_log none
# manager
acl manager proto cache_object
http_access allow manager all
cachemgr_passwd pass all
cache_mgr admin@pig2pig.com
#swap 性能微调
half_closed_clients off
cache_swap_high 100%
cache_swap_low 95%
maximum_object_size 1024 KB
# 控制对象的超时时间 (S_Data-Data)refresh_pattern -i .html 60 90% 10080 reload-into-ims
refresh_pattern -i .png 60 90% 10080 reload-into-ims
refresh_pattern -i .jpg 1440 90% 129600 reload-into-ims
refresh_pattern -i .gif 1440 90% 129600 reload-into-ims
refresh_pattern -i .js 1440 90% 10080 reload-into-ims
refresh_pattern -i .swf 1440 90% 129600 reload-into-ims
refresh_pattern -i .bmp 1440 90% 129600 reload-into-ims
# refresh_pattern -i .shtml 1440 90% 129600 reload-into-ims
# refresh_pattern -i .hml 1440 90% 129600 reload-into-ims
# 禁止缓存
hierarchy_stoplist cgi-bin ?
hierarchy_stoplist -i ^https:\\ ?
acl QUERY urlpath_regex -i cgi-bin \? \.php \.xml
acl denyssl urlpath_regex -i ^https:\\
no_cache deny QUERY
no_cache deny denyssl
#logfile_rotate 可以用logfile_rotate 0来取消自动操作
logfile_rotate 4


C.模式3:Squid 与 Web是同一台服务器
# vi /Data/apps/squid/etc/squid.conf  代码如下:
引用

# visible name
visible_hostname cache.pig2pig.com
# cache config: space use 1G and memory use 256M
   cache_dir ufs /Data/apps/squid/cache 1024 16 256
   cache_mem 256 MB
   cache_effective_user squid  #设置运行时的用户和组权限
cache_effective_group squid
         # 反向加速配置
http_port 80   # squid监听的端口,客户访问网站的端口
httpd_accel_host ip_address  # WEB服务器的IP地址
httpd_accel_single_host on # 设置转发为缓冲的请求到一台单独的机器
httpd_accel_port 81    # WEB服务器的端口
httpd_accel_uses_host_header off  # 完成单台WEB服务器的反向代理功能
httpd_accel_with_proxy off    # 停用代理本地上网
# accelerater my domain only
acl acceleratedHostA dst ip_address # WEB服务器的IP地址
# accelerater http protocol on port 80
acl acceleratedProtocol protocol HTTP
acl acceleratedPort port 80
# access arc
acl all src 0.0.0.0/0.0.0.0
# Allow requests when they are to the accelerated machine
AND to the right port with right protocol
http_access allow acceleratedProtocol acceleratedPort
acceleratedHostA
http_access allow all
# logging
emulate_httpd_log on
cache_store_log none
# manager
acl manager proto cache_object
http_access allow manager all
cachemgr_passwd pass all
cache_mgr admin@pig2pig.com
#swap 性能微调
half_closed_clients off
cache_swap_high 100%
cache_swap_low 95%
maximum_object_size 1024 KB
# 控制对象的超时时间 (S_Data-Data)refresh_pattern -i .html 60 90% 10080 reload-into-ims
refresh_pattern -i .png 60 90% 10080 reload-into-ims
refresh_pattern -i .jpg 1440 90% 129600 reload-into-ims
refresh_pattern -i .gif 1440 90% 129600 reload-into-ims
refresh_pattern -i .js 1440 90% 10080 reload-into-ims
refresh_pattern -i .swf 1440 90% 129600 reload-into-ims
refresh_pattern -i .bmp 1440 90% 129600 reload-into-ims
# refresh_pattern -i .shtml 1440 90% 129600 reload-into-ims
# refresh_pattern -i .hml 1440 90% 129600 reload-into-ims
# 禁止缓存
hierarchy_stoplist cgi-bin ?
hierarchy_stoplist -i ^https:\\ ?
acl QUERY urlpath_regex -i cgi-bin \? \.php \.xml
acl denyssl urlpath_regex -i ^https:\\
no_cache deny QUERY
no_cache deny denyssl
# logfile_rotate 可以用logfile_rotate 0来取消自动操作
logfile_rotate 4


Setp 3 –Starting Squid
1、    创建缓存目录
# cd /Data/apps/squid/sbin
#./squid –z   # 出现Creating Swap Directories提示,表示建立成功
2、    运行Squid
# cd /Data/apps/squid/sbin
#./squid –NCd1 # 成功后将出现"Ready to serve requests".否则请检查配置文件
说明,用squid -NCd1来以debug模式启动,这样如果有错误会报出来,一般如果是ADSL拨号的,那么在没有拨号之前就启动squid的话是会出错的(FATAL: ipcache_init: DNS name lookup tests failed),因为squid启动时会去检查一些常用的DNS,但是这时候你并没有接入internet,自然就出错了,所以我们需要在启动的时候不检查DNS,这就需要用加上-D选项来启动squid,命令如下:
#./squid –NCDd1 # 参数Dd1的目的是禁止测试DNS的连通性并且把squid在开始运行后的一些提示信息显示在屏幕上)
三、 注意事项:
1、Squid的配置文件squid.conf更改后必须重新运行squid;
[/size]
分享到:
评论

相关推荐

    squid反向代理配置例子

    主要例出squid.conf的几种反向代理的配置例子

    Squid 反向代理配置

    Squid 2.6 反向代理配置.doc, Squid 代理配置

    squid for windows反向代理

    利用squid做反向代理服务器,squid反向代理配置

    Squid缓存代理服务器的安装与配置(普通代理 透明代理 反向代理)

    Squid缓存代理服务器的安装与配置(普通代理 透明代理 反向代理)

    Squid for windows 反向代理缓存服务器配置软件

    也就是说,当一个用户想要下载一个主页时,它向Squid发出一个申请,要Squid替它下载,然后Squid 连接所申请网站并请求该主页,接着把该主页传给用户同时保留一个备份,当别的用户申请同样的页面时,Squid把保存的...

    Centos中Squid代理服务器安装和基本设置(含反向代理)

    Centos中Squid代理服务器安装和基本设置(含反向代理) 给网络班的学生上课时使用的简单教学课件。

    nginx配置反向代理

    加上前端squid配置后,问题依然无法解决.而页面程序大部分是动态.无法使用fastcgi来处理.因此想使用nginx做为反向代理apache.整个配置安装过程很简单.在考虑高并发的情况下,在安装前就做了些优化.目前配置能抗住3000...

    centos下简单配置安装Squid 3.0反向代理

    安装篇: 本教程应用环境为干净centos 5.5 ,预先分好并加载/data分区,并且关闭selinux及iptables 首先修改文件描述符并设定临时端口范围,这些设置重启后生效 代码如下: cat >> /etc/security/limits.conf <...

    squid 2.6做代理服务器反向加速内网web

    包括DNS的安装和配置、squid 2.6的安装和配置、apache的安装和配置。做反向代理加速内网web服务器

    Nginx作为反向代理时传递客户端IP的设置方法

    nginx默认配置文件里面是没有进行日志转发配置的,这个需要我们自己手动来操作了,当然后端的...同样适用于前端是 Squid 或者其他反向代理的情况。 首先前端的 Nginx 要做转发客户端 IP 的配置: location / { proxy_p

    linux下通过Squid反向代理搭建CDN缓存服务器的配置方法

    案例:Web服务器:域名www.abc.com IP:192.168.21.129 电信单线路接入访问用户:电信宽带用户、移动宽带用户出现问题:电信用户打开www.abc.com正常,移动用户...配置反向代理搭建CDN缓存服务器安装前准备:1、关闭SE

    nginx反向代理配置及优化.doc

    加上前端squid配置后,问题依然无法解决.而页面程序大部分是动态.无法使用fastcgi来处理.因此想使用nginx做为反向代理apache.整个配置安装过程很简单.在考虑高并发的情况下,在安装前就做了些优化.目前配置能抗住3000...

    squid权威指南 轻松配置代理服务器

    详细介绍squid服务器安装,配置。 轻松实现服务器代理,网络加速。

    Nginx服务器搭建反向代理全攻略

    加上前端squid配置后,问题依然无法解决.而页面程序大部分是动态.无法使用fastcgi来处理.因此想使用Nginx反向代理apache.整个配置安装过程很简单.在考虑高并发的情况下,在安装前就做了些优化.目前配置能抗住3000以上...

    详解nginx反向代理配置及优化

    加上前端squid配置后,问题依然无法解决.而页面程序大部分是动态.无法使用fastcgi来处理.因此想使用nginx做为反向代理apache.整个配置安装过程很简单.在考虑高并发的情况下,在安装前就做了些优化.目前配置能抗住3000...

    squid2.6 windows

    基于windows下的squid 更方便更快捷的设置反向代理服务

    Squid 权威指南

    Squid web加速 透明代理,反向代理, 里面有配置实例和每项功能讲解

    linux_squid服务器详细介绍.txt

    该笔记由博主本人亲自整理撰写,介绍以及各方面的操作都进行了简化提示,很适合linux的萌新进行学习,内容大致:【squid的安装】【正向代理】【反向代理】【ACL访问控制列表】【配置文件简单介绍】【简化记忆】

    squid 2.6 for window

    已经调试安装完成版本,能够实现反向代理和用户认证功能,内含程序配置文件信息。

    nginx学习总结五(nginx反向代理)

    Nginx的Web缓存服务主要由proxy_cache相关指令集和fastcgi_cache相关指令集构成,前者用于反向代理时,对后端内容源服务器进行缓存,后者主要用于对FastCGI的动态程序进行缓存。两者的功能基本上一样。 Nginx 0.8.32...

Global site tag (gtag.js) - Google Analytics