您的位置:首页 > 运维架构 > 反向代理

squid反向代理

2017-06-19 15:05 204 查看
squid反向代理
过程其实和前面的正向代理没有什么太大区别,唯一的区别是配置文件中一个地方需要改动一下。需要把:
http_port 3128
改为:
http_port 80 accel vhost vport
然后再增加你要代理的后端真实服务器信息:
cache_peer 123.125.119.147 parent 80 0 originserver name=a
cache_peer 61.135.169.125 parent 80 0 originserver name=b
cache_peer_domain a www.qq.com
cache_peer_domain b www.baidu.com
因为咱们之前没有配置网站信息,所以就拿qq.com和baidu.com来做个例子吧。其中cache_peer为配置后端的服务器ip以及端口,name后边为要配置的域名,这里和后面的cache_peer_domain相对应。实际的应用中,ip大多为内外ip,而域名也许会有多个,如果是squid要代理一台web上的所有域名,那么就写成这样:
cache_peer 192.168.10.111 80 0 originserver
后面连cache_peer_domain 也省了。
反向代理主要用于缓存静态项,因为诸多静态项目尤其是图片、流媒体等比较耗费带宽,在中国,联通网访问电信的资源本例就慢,如果再去访问大流量的图片、流媒体那更会慢了,所以如果在联通网配置一个squid反向代理,让联通客户端直接访问这个联通squid,而这些静态项已经被缓存在了squid上,这样就大大加快了访问速度。也许你听说过CDN, 其实它的设计原理就是这样的思路。好了,我们再测一测反向代理吧。
因为修改了配置文件,所以需要重启一下squid:
[root@localhost ~]# /etc/init.d/squid restart
[root@localhost ~]# curl -xlocalhost:80 http://www.baidu.com/ [root@localhost ~]# curl -xlocalhost:80 http://www.qq.com/ [root@localhost ~]# curl -xlocalhost:80 http://www.sina.com/ 你会发现,baidu.com和qq.com都能正常访问,然而sina.com访问503了,这是因为并没有加sina.com的相关设置。
还有一个知识点,需要介绍给你:
[root@localhost ~]# squid -h
Usage: squid [-cdhvzCFNRVYX] [-s | -l facility] [-f config-file] [-[au] port] [-k signal]
-a port Specify HTTP port number (default: 3128).
-d level Write debugging to stderr also.
-f file Use given config-file instead of
/etc/squid/squid.conf
-h Print help message.
-k reconfigure|rotate|shutdown|interrupt|kill|debug|check|parse
Parse configuration file, then send signal to
running copy (except -k parse) and exit.
-s | -l facility
Enable logging to syslog.
-u port Specify ICP port number (default: 3130), disable with 0.
-v Print version.
-z Create swap directories
-C Do not catch fatal signals.
-D OBSOLETE. Scheduled for removal.
-F Don't serve any requests until store is rebuilt.
-N No daemon mode.
-R Do not set REUSEADDR on port.
-S Double-check swap during rebuild.
-X Force full debugging.
-Y Only return UDP_HIT or UDP_MISS_NOFETCH during fast reload.
上面把squid命令所用到的选项全部打印出来了,但最常用的除了 squid -k check 外,还有一个那就是 squid -k reconfigure 它们俩都可以简写:
[root@localhost ~]# squid -kche
[root@localhost ~]# squid -krec
其中第二条命令表示重新加载配置文件,如果我们更改了配置文件后,不需要重启squid服务,直接使用该命令重新加载配置即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  squid 反向代理