代理服务器Squid,Nginx

代理服务器:Squid,Nginx

正向代理(透明代理) squid  nginx
     作用:让内网用户上网,缓存(内存,硬盘),加快访问速度,节约通信带宽
             访问控制ACL实现对用户上网行为进行控制(时间、网站、内容...)
          防止内部主机受到攻击
反向代理  squid,nginx
     作用:给网站加速
================================================================
[root@nat-server ~]# iptables -F
[root@nat-server ~]# iptables -t nat -F
[root@nat-server ~]# service iptables save


==squid:
软件包:squid
端口: 3128/tcp默认
配置文件:/etc/squid/squid.conf
日志文件: /var/log/squid


正向代理
client(192.168.2.168)--->eth0(192.168.2.10)squid Server(1.1.1.1)eth1 --> Web(1.1.1.100)
一、配置squid
# yum -y install squid
# vim /etc/squid/squid.conf
http_port 3128          //squid监听的端口
cache_mem 16000 MB     //设置squid内存缓冲大小
cache_dir ufs /var/spool/squid 50000 16 256     //设置squid硬盘缓冲大小
cache_effective_user squid
cache_effective_group squid
dns_nameservers 202.106.0.20 8.8.8.8
cache_mgr tianyun@126.com

===========================================================
# service squid start
init_cache_dir /var/spool/squid... /etc/init.d/squid: line 62:  5504 已放弃              
$SQUID -z -F -D >> /var/log/squid/squid.out 2>&1
启动 squid:/etc/init.d/squid: line 42:  5505 已放弃              
$SQUID $SQUID_OPTS >> /var/log/squid/squid.out 2>&1
[失败]

visible_hostname squid
=========================================================

# service squid start
# chkconfig squid on
[root@nat-server ~]# netstat -tnlp |grep :3128
tcp        0      0 0.0.0.0:3128         0.0.0.0:*   LISTEN      5526/(squid) 

从客户端测试代理服务器:
浏览器:需要手工设置代理
测试结果:代理服务默认不为任何主机代理


解决方案:
ACL,限制用户访问(时间、目标网站、内容...)
# vim /etc/squid/squid.conf
/INSERT
方案一:为所有主机代理
acl all src 0.0.0.0/0.0.0.0
http_access allow all

方案二:为部分主机代理
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
acl it_net src 192.168.2.0/24
http_access allow it_net
# service squid reload


案例1:允许192.168.2.0/24网段的主机使用squid
acl it_net src 192.168.2.0/24
http_access allow it_net

案例2: 允许192.168.2.0/24网段的主机使用squid,(周一到周五 9:00-16:00)
acl it_net src 192.168.2.0/24
acl worktime time MTWHF 9:00-16:00
http_access allow it_net worktime

案例3 拒绝主机
acl wangcheng src 192.168.2.168
http_access deny wangcheng

案例4 禁止用户访问URL包含qq.com网站,-i忽略大小写
acl disable_web url_regex -i qq.com
http_access deny disable_web

案例5 禁止用户下载*.mp3 *.exe *.iso
acl disable_down urlpath_regex -i \.mp3$ \.exe$ \.iso$                 \\ . 点需要转义下,不转义的话代表任意单个字符。
http_access deny disable_down

=============================================================
acl all src 0.0.0.0/0.0.0.0
acl it_net src 192.168.2.0/24
acl hr_net src 192.168.3.0/24
acl worktime time MTWHF 9:00-16:00
acl disable_web url_regex -i qq.com
acl disable_down urlpath_regex -i \.mp3$ \.exe$ \.iso$
acl wangcheng src 192.168.2.168

http_access deny wangcheng
http_access deny disable_down
http_access deny disable_web
http_access allow it_net
http_access allow hr_net worktime
http_access deny all
=============================================================

透明代理(以正向代理为基础)
代理服务器:IP 192.168.2.10
          http_port: 3128
1. iptables数据包重定向
[root@squid-server ~]# iptables -t nat -F
[root@squid-server ~]# iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to 3128
[root@squid-server ~]# service iptables save

2. squid支持透明代理
[root@squid-server ~]# vim /etc/squid/squid.conf
http_port 3128 transparent
[root@squid-server ~]# service squid reload

注意:客户端必须将数据包发给代理服务器


反向代理
============================
[root@squid-server ~]# service iptables stop
client(192.168.2.115)--->          前端反向代理服务器(192.168.2.10) --> Web(192.168.2.108)
本身已经可以访问Internet          前端反向代理服务器(192.168.2.168)     前端反向代理服务器(192.168.2.169)。。。。。。。。。。。。。。。    
一、配置squid
# service iptables stop
# yum -y install squid
# vim /etc/squid/squid.conf
cache_mem 16000 MB     //设置squid内存缓冲大小
cache_dir ufs /var/spool/squid 50000 16 256     //设置squid硬盘缓冲大小,
cache_effective_user squid
cache_effective_group squid
dns_nameservers 202.106.0.20 8.8.8.8
cache_mgr tianyun@126.com

http_port 80 vhost     //反向代理
cache_peer 192.168.2.108 parent 80 0          //源站
acl all src 0.0.0.0/0.0.0.0
http_access allow all

cache_peer Web服务器地址 服务器类型 http端口 icp端口 选项
cache_peer 192.168.2.108 parent 80 0

=========================================================
给一个源站做反向代理
cache_peer 192.168.2.108 parent 80 0         

给多个源站做反向代理
cache_peer 192.168.2.100 parent 80 0 originserver weight=1 name=tianyun
cache_peer 192.168.2.120 parent 80 0 originserver weight=1 name=uplooking
cache_peer 192.168.2.130 parent 80 0 originserver weight=1 name=126
cache_peer_domain tianyun www.tianyun.com
cache_peer_domain uplooking www.uplooking.com
cache_peer_domain 126 www.126.com
============================================================
如果启动失败,检查80端口是否被占用


从客户端测试:必须使用域名访问
/etc/hosts
192.168.2.10     www.tianyun.com www.uplooking.com www.126.com
反向代理服务器


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!对于nginxsquid的反向代理实验,我可以为您提供一些基本的指导和概念说明。 首先,nginxsquid都是常用的反向代理服务器软件。它们的主要功能是接收客户端请求,并将这些请求转发到后端的服务器上,然后将响应返回给客户端。这种反向代理的架构可以提供负载均衡、缓存、安全性等优势。 在进行实验之前,您需要确保已经安装了nginxsquid。安装方法可以参考官方文档或者相关的教程。 对于nginx,您可以通过修改nginx配置文件来配置反向代理。主要的配置项是`proxy_pass`,它指定了需要转发的后端服务器地址。您可以根据需要添加其他的配置项,如负载均衡策略、缓存设置等。 下面是一个简单的nginx反向代理配置示例: ```nginx server { listen 80; server_name example.com; location / { proxy_pass http://backend_server; } } ``` 在上面的示例中,所有请求都会被转发到`http://backend_server`这个后端服务器上。 对于squid,您可以通过编辑squid配置文件来配置反向代理。主要的配置项是`cache_peer`,它指定了需要转发的后端服务器地址。您可以根据需要添加其他的配置项,如缓存设置、访问控制等。 下面是一个简单的squid反向代理配置示例: ``` http_port 3128 http_access allow all cache_peer backend_server parent 80 0 no-query originserver acl our_sites dstdomain example.com http_access allow our_sites cache_peer_access backend_server allow our_sites ``` 在上面的示例中,squid监听在3128端口,所有请求都会被转发到`backend_server`这个后端服务器上。同时,针对example.com这个域名的请求会被允许访问。 请注意,以上只是简单的示例配置,实际的配置可能还涉及到其他方面的设置,如安全性、性能优化等。 希望以上信息能对您有所帮助!如果您有任何进一步的问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值