反向代理(反向加速代理)

1对1

[web]---[squid]----internet
client
192.168.1.8   192.168.1.249 192.168.2.249 192.168.2.2
8080

squid server
需要有公网IP,需要在DNS上做好web服务域名和IP的对应关系:

www.51cto.com ---- 192.168.2.249

1、安装squid软件包
yum -y install squid
2、配置squid
574 acl all src 0.0.0.0/0.0.0.0

637 #http_access deny all
638 http_access allow all
639
921 http_port 80 accel vhost vport
accel 表示反向加速模式使用
vhost 在使用accel时,至少要加vhost,表示后面web服务器是基于域名的虚拟主机。
vport 如果后端 的web服务器是基于ip的虚拟主机,则使用

1183 cache_peer 192.168.1.8 parent 8080 0 originserver

3、启动squid(80端口已经被占用,如apache)
[root@localhost spool]# netstat -tnlp | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 21040/(squi

4、客户端验证
访问 squid的外网卡的80端口,看是否可以访问到内部的web服务器的页面信息
]# ab -n 1000 -c 1000 http://192.168.2.249/index.html
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.2.249 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Finished 1000 requests

Server Software: Apache/2.2.3
Server Hostname: 192.168.2.249
Server Port: 80

Document Path: /index.html
Document Length: 17 bytes

Concurrency Level: 1000
Time taken for tests: 0.483220 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 436000 bytes
HTML transferred: 17000 bytes
Requests per second: 2069.45 [#/sec] (mean)
Time per request: 483.220 [ms] (mean)
Time per request: 0.483 [ms] (mean, across all concurrent requests)
Transfer rate: 879.52 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 1 70 41.2 70 148
Processing: 45 177 79.2 175 384
Waiting: 44 175 78.8 174 384
Total: 58 247 91.7 276 385

Percentage of the requests served within a certain time (ms)
50% 276
66% 307
75% 319
80% 326
90% 348
95% 379
98% 384
99% 385
100% 385 (longest request)

1对多

后端 web服务器是相同内容

squid server
需要有公网IP,需要在DNS上做好web服务域名和IP的对应关系:

后端 web服务器是相同内容
192.168.1.8:8080 \
192.168.1.15:800 - squid----------------client
192.168.1.34:80 /
192.168.1.249 192.168.2.2
192.168.2.249

做DNS解析时: www.51cto.com ---- 192.168.2.249

1、安装squid软件包
yum -y install squid
2、配置squid
574 acl all src 0.0.0.0/0.0.0.0

637 #http_access deny all
638 http_access allow all
639
921 http_port 80 accel vhost vport
accel 表示反向加速模式使用
vhost 在使用accel时,至少要加vhost,表示后面web服务器是基于域名的虚拟主机。
vport 如果后端 的web服务器是基于ip的虚拟主机,则使用

#cache_peer 192.168.1.8 parent 8080 0 originserver
cache_peer 192.168.1.8 parent 8080 0 round-robin
cache_peer 192.168.1.15 parent 800 0 round-robin
cache_peer 192.168.1.34 parent 80 0 round-robin
3、启动squid(80端口已经被占用,如apache)
[root@localhost spool]# netstat -tnlp | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 21040/(squid)

4、客户端测试
]# elinks -dump http://192.168.2.249/

后端 web服务器是不相同内容

后端 web服务器是不相同内容

51cto1 192.168.1.8:8080 \
51cto2 192.168.1.34:800 - squid----------------client
51cto3 192.168.1.15:80 /
192.168.1.249 192.168.2.2
192.168.2.249

做DNS解析时: www.51cto1.com ---- 192.168.2.249
www.51cto2.com ---- 192.168.2.249
www.51cto3.com ---- 192.168.2.249
注意:如果不想搭建DNS,请在客户端/etc/hosts文件中暂时定义测试一下

1、安装squid软件包
yum -y install squid
2、配置squid
574 acl all src 0.0.0.0/0.0.0.0

637 #http_access deny all
638 http_access allow all
639
921 http_port 80 accel vhost vport
accel 表示反向加速模式使用
vhost 在使用accel时,至少要加vhost,表示后面web服务器是基于域名的虚拟主机。
vport 如果后端 的web服务器是基于ip的虚拟主机,则使用

#cache_peer hostname type http-port icp-port [options]
##
#cache_peer 192.168.1.8 parent 8080 0 originserver
#cache_peer 192.168.1.8 parent 8080 0 round-robin weight=1
#cache_peer 192.168.1.15 parent 800 0 round-robin weight=1
#cache_peer 192.168.1.34 parent 80 0 round-robin weight=1
cache_peer 192.168.1.8 parent 8080 0 originserver name=51cto1
cache_peer 192.168.1.34 parent 80 0 originserver name=51cto2
cache_peer 192.168.1.15 parent 800 0 originserver name=51cto3

#cache_peer_domain cache-host domain [domain ...]
cache_peer_domain 51cto1 www.51cto1.com
cache_peer_domain 51cto2 www.51cto2.com
cache_peer_domain 51cto3 www.51cto3.com

cache_peer_access 51cto1 allow all
cache_peer_access 51cto2 allow all
cache_peer_access 51cto3 allow all
#注意这里的all是已经定义的acl名称,表示允许所有ip的客户端访问51cto1,51cto2,51cto3
# cache_peer_access cache-host allow|deny [!]aclname ...

3、启动squid(80端口已经被占用,如apache)
service squid restart
[root@localhost spool]# netstat -tnlp | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 21040/(squid)

4、客户端测试(的确可以通过域名访问到后端的对应的web服务器)
[root@localhost ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.2.249 www.51cto1.com
192.168.2.249 www.51cto2.com
192.168.2.249 www.51cto3.com

]# elinks -dump http://www.51cto1.com/
]# elinks -dump http://www.51cto2.com/
]# elinks -dump http://www.51cto3.com/

[root@localhost ~]# elinks -dump http://www.51cto1.com/
Welcome to 192.168.1.8:8080
[root@localhost ~]# elinks -dump http://www.51cto2.com/
192.168.1.34
[root@localhost ~]# elinks -dump http://www.51cto3.com/
welcome to 192.168.1.15

转载于:https://blog.51cto.com/jeffreylee/564574

代理服务之反向代理(反向加速代理)相关推荐

  1. squid正向代理 反向代理 CDN加速

    文章目录 一.squid正向代理 反向代理 CDN加速. 1.正向代理 1.1如何实现正向代理 2.反向代理 2.1 如何实现反向代理 3.CDN加速 3.1.如何实现CDN加速 一.squid正向代 ...

  2. Squid代理(传统代理、透明代理、反向代理)、日志分析、ACL访问控制

    Squid代理(传统代理.透明代理.反向代理).日志分析.ACL访问控制 一.Squid代理服务器 1.代理的工作机制 2.代理的类型 二.安装Squid服务 1.编译安装Squid 2.修改Squi ...

  3. 构建Squid代理服务器-传统代理、透明代理、反向代理

    Squid是Linux系统中最常用的一款开源代理服务软件,主要提供缓存加速和应用层过滤控制的功能,可以很好的实现HTTP.FTP.DNS查询以及SSL等应用的缓存代理. 正向代理: 根据实现的方式不同 ...

  4. 彻底理解正向代理、反向代理、透明代理

    套用古龙武侠小说套路来说,代理服务技术是一门很古老的技术,是在互联网早期出现就使用的技术.一般实现代理技术的方式就是在服务器上安装代理服务软件,让其成为一个代理服务器,从而实现代理技术.常用的代理技术 ...

  5. 反向代理和正向代理详解

    反向代理 引言: 反向代理服务是我们日常生活中常见会用到的技术,比如我们访问京东jd.com,我们的访问请求会发送给京东的代理服务器,由代理服务器将访问请求发送给京东服务器,所以我们其实并不知道实际访 ...

  6. 代理,正向代理和反向代理

    1. 代理 代理也被叫做网络代理,是一种比较特殊的网络服务,允许一个终端(通常指客户端)通过这个服务与另一个终端(通常指服务器端)进行非直接的连接. 例如:一些网关.路由器等网络设备都具备网络代理的功 ...

  7. 端口转发映射详解、代理反向代理深入认知

    端口转发&&端口映射 端口转发和端口映射都是为了解决内网主机的端口无法在外部直接访问而衍生出来的技术,通过中间服务器进行中转,将内部的端口映射到公网IP上或者将内部端口转发到外部服务器 ...

  8. 图解正向代理、反向代理、透明代理

    内容出自:http://z00w00.blog.51cto.com/515114/1031287 套用古龙武侠小说套路来说,代理服务技术是一门很古老的技术,是在互联网早期出现就使用的技术.一般实现代理 ...

  9. 什么是nginx?什么是nginx的反向代理和正向代理又是什么?nginx反向代理的作用?

    1. nginx 1.1 nginx简介 Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点(俄 ...

最新文章

  1. 出让执行权:Task.Yield, Dispathcer.Yield
  2. css实现loading,CSS3 19种LOADING(加载)动效
  3. puppeteer 鼠标定位滑块_监听滑块滑动或滑块随鼠标移动 | JShare
  4. Python新手输出代码
  5. Lua开发工作笔记0004---交互式编程与脚本式编程及注释的写法
  6. 30个你 “ 不可能全部会做 ” 的javascript题目
  7. javascript实现浏览器窗口传递参数
  8. 宝塔控制面板配置Nginx 安全证书
  9. mybatis的二表联合查询
  10. [Python3 填坑] 008 索引君的朋友 in
  11. Ubuntu 上安装 Node.js
  12. mysql 索引超出范围_java.sql.SQLException:列索引超出范围,0 1
  13. 教学|zbrush雕刻头发笔刷介绍,巧用工具可以事半功倍哦!
  14. 【管理学】行业KOL——关键意见领袖(达人效应)
  15. HHKB连不上Ubuntu
  16. 如何在文字上划横线_word怎么在字上划线的两种方法
  17. java jsoup jar包_jsoup jar包
  18. 写一个strncpy(char *dest, const char *src, size_t cpy_lent) 的函数
  19. False data injection attacks and the insider threat in smart systems
  20. flex布局文本不换行

热门文章

  1. 智能重卡产品研发的三种逻辑博弈
  2. 精选——Hive十道面试题(下)
  3. 内卷失败:敲了 10000 小时代码,我也没能成为一名高级程序员
  4. 百度地图瓦片层级范围对照表
  5. VirtualBox下Centos7安装增强功能
  6. 基于遗传算法在机器人路径规划中的应用研究(Matlab代码实现)
  7. Pocket英语语法---六、感官动词接不同的动词表示什么意思
  8. 大数据技术基础实验十三:Kafka实验——订阅推送示例
  9. 字符串全排列算法_C#版_剑指OFFER
  10. 算法:去除英文文本中重复单词