Centos 6.4下用Squid配置反向代理多个内网WEB服务器

前端之家收集整理的这篇文章主要介绍了Centos 6.4下用Squid配置反向代理多个内网WEB服务器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Centos 6.4下用Squid配置反向代理多个内网WEB服务器

源贴1:http://www.cnblogs.com/daretodream/archive/2013/04/27/3046975.html

源贴1:http://jingyan.baidu.com/article/7e440953ed4c7f2fc0e2efdd.html


  1. http_port80accelvport
  2. visible_hostnamebogon
  3. cache_mem128MB
  4.  
  5. maximum_object_size_in_memory2048KB
  6.  
  7. memory_replacement_policylru
  8.  
  9. cache_dirufs/usr/local/squid/var/cache/squid51216256access_log/usr/local/squid/var/logs/access.log
  10.  
  11. cache_log/usr/local/squid/var/logs/cache.log
  12.  
  13. max_open_disk_fds0minimum_object_size0KB
  14.  
  15. maximum_object_size32768KB
  16.  
  17. #logformatcombined%>a%ui%un[%tl]"%rm%ruHTTP/%rv"%Hs%<st"%{Referer}>h""%{User-Agent}>h"%Ss:%Sh
  18.  
  19. cache_peer192.168.20.17parent800no-queryno-digestoriginservername=oa
  20. cache_peer10.19.113.3parent800no-queryno-digestoriginservername=ob
  21.  
  22. #需要反向代理的源WEB服务器,可以添加多个,若只有一个源WEB服务器,可不设name
  23.  
  24.  
  25.  
  26. #需要反向代理的源WEB服务器,可以添加多个
  27.  
  28. cache_peer_domainoaoa.XXX.com.cn
  29. cache_peer_domainobob.XXX.com.cn
  30.  
  31. #若只有一个源WEB服务器,可不设cache_peer_domain
  32.  
  33.  
  34. http_accessallowall
  35.  
  36. cache_effective_usernobody
  37.  
  38. cache_effective_groupnobody
  39.  
  40. cache_mgrzifu.199s0@163.com
  41.  
  42. #refresh_pattern^ftp:6020%10080
  43. #refresh_pattern^gopher:600%1440
  44. #refresh_pattern^gopher:600%1440
  45. #refresh_pattern.020%1440
  46. refresh_pattern-i\.css$36050%2880
  47. refresh_pattern-i\.js$144050%2880
  48. refresh_pattern-i\.html$72050%1440
  49. refresh_pattern-i\.jpg$144090%2880
  50. refresh_pattern-i\.gif$144090%2880
  51. refresh_pattern-i\.swf$144090%2880
  52. refresh_pattern-i\.jpg$144050%2880
  53. refresh_pattern-i\.png$144050%2880
  54. refresh_pattern-i\.bmp$144050%2880
  55. refresh_pattern-i\.doc$144050%2880
  56. refresh_pattern-i\.ppt$144050%2880
  57. refresh_pattern-i\.xls$144050%2880
  58. refresh_pattern-i\.pdf$144050%2880
  59. refresh_pattern-i\.rar$144050%2880
  60. refresh_pattern-i\.zip$144050%2880
  61. refresh_pattern-i\.txt$144050%2880

Squid反向代理一个及多个后台WEB服务器方


1.Squid反向代理单个后台WEB服务器

A、如果WEB服务器和反向代理服务器是两台单独的机器(一般的反向代理应该有两块网卡分别连接了内外部网络)。那么,应该修改下面的内容来设置反向代理服务。

http_port 80 # squid监听的端口

httpd_accel_host 192.168.0.100 # 内部WEB服务器的IP地址

httpd_accel_port 80 # WEB服务器的IP地址

httpd_accel_single_host on # 转发为缓冲的请求到一台单独的机器

httpd_accel_with_proxy on #

httpd_accel_uses_host_header off

B、如果WEB服务器和反向代理服务器是同一台机器。那么,应该设置WEB服务器的监听端口为非80端口(比如:81端口)。要修改内容如下:

http_port 80 # squid监听的端口

httpd_accel_host localhost # 内部WEB服务器的IP地址

httpd_accel_port 81 # WEB服务器的IP地址

httpd_accel_single_host on # 转发为缓冲的请求到一台单独的机器

httpd_accel_with_proxy on #

httpd_accel_uses_host_header off

下面解释一下配置指令:

http_port 80

选项 http_port 指定squid监听HTTP请求的端口,一般都设置成80端口,这样使用户感觉不到反向代理的存在,就像访问真正的WEB服务器一样。

httpd_accel_host 192.168.0.100 和 httpd_accel_port 80

选项httpd_accel_host 和 httpd_accel_port 指定WEB服务器的IP地址和端口号,可以根据自己的WEB服务器的实际情况而定。

httpd_accel_single_host on

选 项httpd_accel_single_host 为on 时,squid被设置成仅对单一的web服务器作反向代理。不考虑HTTP头信息,Squid转发所有的为被缓冲的页面请求到这个web服务器。如果 squid需要做多个web服务器反向代理,必须将此选项设置为off,并且使用转向器或者DNS去映射请求到合适的后台WEB服务器。

httpd_accel_with_proxy on

如果希望squid既作反向代理服务器又作本地机器的上网代理,需要将httpd_accel_with_proxy 改为 on,默认情况下是off

httpd_accel_uses_host_header off

在HTTP协议1.1中,HTTP请求包括一个主机头信息,指定URL的主机名或者主机的IP地址。这个选项可以用来完成多个后台WEB服务器的反向代理功能

2. Squid反向代理多个后台WEB服务器

我们可以用Squid反向代理多个后台WEB服务器。例如:我们可以配置squid同时反向代理www.xxx.com www.yyy.com www.zzz.com 三个后台WEB服务器。

Squid的配置如下:

httpd_accel_host virtual

httpd_accel_port 80

httpd_accel_single_host off

httpd_accel_uses_host_header on

注意:编译Squid时需激活Internal DNS选项

--disable-internal-dns

一个比较全的编译配置如下:

./configure --prefix=/usr/local/squid --enable-dlmalloc --with-pthreads --enable-poll --disable-internal-dns --enable-stacktrace --enable-removal-policies="heap,lru" --enable-delay-pools --enable-storeio="aufs,coss,diskd,ufs"

然后设置设置反响代理需要的域名解析(加入hosts)如下:

www.xxx.com 111.222.333.444

www.yyy.com 111.222.333.444

www.zzz.com 111.222.333.444

使三个域名都指向反向代理服务器的IP地址111.222.333.444。

下面设置反向代理所需要的DNS入口信息(即设置内部DNS,仅仅是squid在内部使用,Internet用户不可见)。有两种方法可以设置内部DNS,使用内部DNS服务器来解析或者使用/etc/hosts文件来实现。

使用内部DNS服务器的资源记录如下:

www.xxx.com IN A 192.168.0.101

www.yyy.com IN A 192.168.0.102

www.zzz.com IN A 192.168.0.103

如果使用/etc/hosts文件来实现内部DNS(编译时应使用disable internal dns选项),编辑/etc/hosts文件添加如下条目:

192.168.0.101 www.xxx.com

192.168.0.102 www.yyy.com

192.168.0.103 www.zzz.com

猜你在找的CentOS相关文章