阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

RHEL6.4 搭建Squid反向代理服务器

111次阅读
没有评论

共计 2353 个字符,预计需要花费 6 分钟才能阅读完成。

实验需求:使用 squid 搭建反向代理服务器,在内网服务器 192.168.100.1 上启用基于域名的虚拟主机,使客户端能通过域名访问 www.linuxidc.com 和 bbs.linuxidc.com                                                                         

                                    内网接口 eth0(192.168.1.254)

 内网 web 服务器 192.168.100.1———- squid 反向代理服务器 ————- 公网客户端 1.1.1.1

                                    公网接口 eth1(1.1.1.254)

一. 配置内网的网站服务器 192.168.100.1

可以使用 apache 或 nginx 等软件搭建,本实验采用 nginx 搭建

1. 安装 nginx 软件并编辑配置文件

# vim /usr/local/nginx/conf/nginx.conf

http {

  ……

    server  {

        listen  80;

        server_name  www.linuxidc.com;

          location  /  {

                  root  /www;

                  index  index.html;

        }

    }

    server  {

        listen  80;

        server_name  bbs.linuxidc.com;

        location  /  {

                  root  /bbs;

                  index  index.html;

 

        }

  }

  ……

2. 制作测试网页文件

# mkdir /www

# mkdir /bbs

# echo www.linuxidc.com > /www/index.html

# echo bbs.linuxidc.com > /bbs/index.html

3. 启动服务

# cd /usr/local/nginx/sbin

# ./nginx

二. 配置 squid 反向代理服务器

1. 安装软件

# yum -y install squid

2. 编辑配置文件

# vim /etc/squid/squid.conf

……

# And finally deny all other access to this proxy

#http_access deny all

http_access allow all

# Squid normally listens to port 3128

http_port 80 vhost                                        // 监听 80 端口让客户端访问

cache_peer 192.168.100.1 parent 80 0 originserver name=www

cache_peer 192.168.100.1 parent 80 0 originserver name=bbs

cache_peer_domain www www.linuxidc.com

cache_peer_domain bbs bbs.linuxidc.com

 

# We recommend you to use at least the following line.

hierarchy_stoplist cgi-bin ?

cache_mem 8 MB

minimum_object_size 0 KB

maximum_object_size 4096 KB

cache_swap_low 90

cache_swap_high 95

# Uncomment and adjust the following to add a disk cache directory.

cache_dir ufs /var/spool/squid 100 16 256

……

3. 释放 80 端口并启动服务

# service httpd stop              // 本服务器若已启动网站服务则关闭,或将其开启在别的端口

# chkconfig httpd off

# service iptables stop

# chkconfig iptables off

# service squid start

# chkconfig squid on

# netstat -tulnp | grep :80

tcp  0  0 :::80    :::*    LISTEN    3007/(squid)

三. 客户端 1.1.1.1 测试

生产环境将 www.linuxidc.com 及 bbs.linuxidc.com 在 DNS 服务器内指向反向代理服务器 1.1.1.254

测试环境在本机编辑 hosts 文件解析域名对应的 IP 

# vim /etc/hosts

1.1.1.254 www.linuxidc.com

1.1.1.254 bbs.linuxidc.com

# elinks -dump http://www.linuxidc.com             

  www.linuxidc.com

# elinks -dump http://bbs.linuxidc.com

  bbs.linuxidc.com

Squid 的详细介绍 :请点这里
Squid 的下载地址 :请点这里

配置 Squid 代理 http 和 rsync http://www.linuxidc.com/Linux/2013-05/84642.htm

Squid:实现高速的 Web 访问 http://www.linuxidc.com/Linux/2013-04/83512.htm

CentOS 6.2 编译安装 Squid 配置反向代理服务器 http://www.linuxidc.com/Linux/2012-11/74529.htm

简单配置 Squid 代理和反向代理 http://www.linuxidc.com/Linux/2014-04/99465.htm

CentOS 6.4 下 DNS+Squid+Nginx+MySQL 搭建高可用 Web 服务器 http://www.linuxidc.com/Linux/2014-04/99984.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计2353字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中