squid 代理服务

一、正向代理

[[email protected] ~]# yum install -y squid
[[email protected] ~]# squid -v      //查看squid版本
Squid Cache: Version 3.1.10
[[email protected] ~]# rm -f /etc/squid/squid.conf     //不使用默认配置
[[email protected] ~]# vim /etc/squid/squid.conf
//加入
http_port 3128
acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
acl localnet src 10.0.0.0/8     # RFC1918 possible internal network
acl localnet src 172.16.0.0/12  # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl SSL_ports port 443
acl Safe_ports port 80 8080         # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443         # https
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localnet
http_access allow localhost
http_access allow all
cache_dir aufs /data/cache 1024 16 256
cache_mem 128 MB
hierarchy_stoplist cgi-bin ?
coredump_dir /var/spool/squid
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern \.(jpg|png|gif|mp3|xml) 1440    50%     2880    ignore-reload
refresh_pattern .               0       20%     4320

[[email protected] ~]# squid -kcheck      //检测一下是否有语法错误
1.提示信息: squid: ERROR: No running copy

-->  squid还未启动,没有关系,显示成这样说明配置文件没有问题了。

2. 提示信息: WARNING: Could not determine this machines public hostname. Please configure one or set ‘visible_hostname‘.

-->
[[email protected] ~]# vim /etc/squid/squid.conf
//加入
visible_hostname aminglinux.com    #可自定义

[[email protected] ~]# mkdir -p /data/cache    //初始化缓存目录
[[email protected] ~]# chown -R squid:squid /data/cache/
[[email protected] ~]# squid -z
2013/06/12 16:25:14| Creating Swap Directories
2013/06/12 16:25:14| /data/cache exists
//初始化完成
[[email protected] ~]# /etc/init.d/squid start
正在启动 squid:.                                          [确定]

测试:

1.  

[[email protected] ~]# curl -xlocalhost:3128  http://www.baidu.com/
//看到了一大串,说明squid正向代理设置ok

2.

[[email protected]calhost ~]# curl -xlocalhost:3128 http://www.lishiming.net/static/image/common/logo.png -I
HTTP/1.0 200 OK
Server: nginx/1.0.0
Date: Sat, 08 Jun 2013 04:30:17 GMT
Content-Type: image/png
Content-Length: 7785
Last-Modified: Wed, 13 Jan 2010 03:33:47 GMT
Accept-Ranges: bytes
X-Cache: HIT from dx_cache216.5d6d.com
X-Cache: MISS from localhost.localdomain
X-Cache-Lookup: MISS from localhost.localdomain:3128
Via: 1.0 dx_cache216.5d6d.com:80 (squid), 1.0 localhost.localdomain (squid/3.1.10)
Connection: keep-alive

[[email protected] ~]# curl -xlocalhost:3128 http://www.lishiming.net/static/image/common/logo.png -I
HTTP/1.0 200 OK
Server: nginx/1.0.0
Content-Type: image/png
Content-Length: 7785
Last-Modified: Wed, 13 Jan 2010 03:33:47 GMT
Accept-Ranges: bytes
Date: Sat, 08 Jun 2013 04:30:17 GMT
X-Cache: HIT from dx_cache216.5d6d.com
Age: 360898
Warning: 113 localhost.localdomain (squid/3.1.10) This cache hit is still fresh and more than 1 day old
X-Cache: HIT from localhost.localdomain
X-Cache-Lookup: HIT from localhost.localdomain:3128
Via: 1.0 dx_cache216.5d6d.com:80 (squid), 1.0 localhost.localdomain (squid/3.1.10)
Connection: keep-alive

3.  配置白名单 ,表示机器只可以访问白名单的网站 

[[email protected] ~]# vim /etc/squid/squid.conf
...
...
acl CONNECT method CONNECT
#在此下面添加
acl http proto HTTP
acl good_domain dstdomain .lishiming.net .aminglinux.com
http_access allow http good_domain
http_access deny http !good_domain

[[email protected] ~]# /etc/init.d/squid restart
[[email protected] ~]# curl -xlocalhost:3128 http://www.baidu.com/ -I
HTTP/1.0 403 Forbidden
Server: squid/3.1.23
Mime-Version: 1.0
Date: Fri, 15 Apr 2016 16:32:28 GMT
Content-Type: text/html
Content-Length: 3274
X-Squid-Error: ERR_ACCESS_DENIED 0
Vary: Accept-Language
Content-Language: en
X-Cache: MISS from localhost.localdomain
X-Cache-Lookup: NONE from localhost.localdomain:3128
Via: 1.0 localhost.localdomain (squid/3.1.23)
Connection: keep-alive

4.  配置黑名单,表示机器不可以访问黑名单
acl http proto HTTP
acl bad_domain dstdomain .sina.com .souhu.com
http_access allow http !bad_domain
http_access deny http bad_domain

===============我是分割线。==============================

二、反向代理

[[email protected] ~]# vim /etc/squid/squid.conf
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

[[email protected] ~]# /etc/init.d/squid restart
[[email protected] ~]# curl -xlocalhost:80 http://www.baidu.com/ -I
[[email protected] ~]# curl -xlocalhost:80 http://www.qq.com/ -I
[[email protected] ~]# curl -xlocalhost:80 http://www.sina.com/ -I
#您会发现,baidu.com和qq.com都能正常访问,然而sina.com访问503了

===============我是分割线。==============================

三、squid使用选项

1 。
[[email protected] ~]# 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.

2.
[[email protected] ~]# squid -kche   //==squid -kcheck
[[email protected] ~]# squid -krec    //重加载
时间: 2024-08-27 16:12:30

squid 代理服务的相关文章

squid代理服务简单配置

Squid做为应用层的代理服务软件,squid主要用于提供缓存加速,应用层过滤控制的功能. 工作机制: 当客户机通过代理来请求web页面时,指定的大力服务器会先检查自己的缓存,如果缓存中已经有客户机需要的页面,则直接将缓存中的页面内容反馈给客户机:如果缓存中没有客户机要访问的页面,则有代理服务器向Internet发送请求,当获得返回的web页面以后,将网页数据保存到缓存中并发送给客户机. 代理服务器squid的好处:1,.提高了客户机的web访问响应速度.2.由于客户机的web请求是由代理服务器

RHCE 第18节课 Openldap目录服务和Squid代理服务

今天老师讲了两个部分的内容,分别的目录服务Openldap 和Squid 代理服务,openldap比较难理解,squid代理服务分为正向代理模式和反向代理模式,各有各的用处. 原文地址:https://blog.51cto.com/12331786/2459147

运维学习之squid代理服务

squid 一.squid是什么? 1.Squid是一个高性能的代理缓存服务器,Squid支持FTP.gopher和HTTP协议.和一般的代理缓存软件不同,Squid用一个单独的.非模块化的.I/O驱动的进程来处理所有的客户端请求. 2.Squid是一种用来缓冲Internet数据的软件.它是这样实现其功能的,接受来自人们需要下载的目标(object)的请求并适当地处理这些请求.也就是说,如果一个人想下载一web页面,他请求Squid为他取得这个页面.Squid随之连接到远程服务器(比如:htt

squid代理服务

一:squid传统代理服务 1.编译安装squid 2.创建链接文件,用户和组 3.修改squid配置文件 4.启动squid服务并成功看到3128端口开启 5.编写防火墙规则 6.配置客户端网络代理 7.客户机验证可以通过代理访问服务器 二:透明代理 1.改配置文件 2.新建防火墙规则 三:squid日志分析sarg服务 1.配置本地yum源并安装GD库 2.编译安装sarg服务 3.修改sarg配置文件 4.优化并运行sarg和httpd服务 5.客户机验证可以正常使用sarg工具

Squid代理服务ACL访问控制及日志分析

对于Squid服务的部署可以参考博文:Squid代理服务器安装及部署对于Squid服务配置代理服务器可以参考博文:利用Squid构建传统代理及透明代理 Squid服务的ACL访问控制 Squid提供了强大的代理控制机制,通过合理设置ACL(访问控制列表)并进行限制,可以针对源地址.目标地址.访问的URL路径.访问的时间等各种条件进行过滤. 在配置文件squid.conf中,ACL访问控制通过两个步骤来实现: 使用acl配置项定义需要控制的条件: 通过http_access配置项对已经定义的列表做

Linux的squid代理服务

一.squid简介 代理服务器英文全称是Proxy Server,其功能就是代理网络用户去取得网络信息.Squid是一个缓存Internet 数据的软件,其接收用户的下载申请,并自动处理所下载的数据.当一个用户想要下载一个主页时,可以向Squid 发出一个申请,要Squid 代替其进行下载,然后Squid 连接所申请网站并请求该主页,接着把该主页传给用户同时保留一个备份,当别的用户申请同样的页面时,Squid 把保存的备份立即传给用户,使用户觉得速度相当快.Squid 可以代理HTTP.FTP.

QQ使用squid代理服务登陆 离线 图片 失败

废话先不多说,直接上解决方案: squid.conf    里面增加   acl SSL_ports port 443 80 原因是因为 发图片的时候,离线截图是走tcp 80端口的 亲测可用.

42.部署Squid代理服务

Squid代理服务器 Squid代理服务器工作在应用层,主要提供缓存加速,应用层过滤控制等功能. Squid代理的工作机制: 当客户机通过代理来请求web页面时,指定的代理服务器会先检查自己的缓存,如果缓存中有数据则直接反馈给客户机,如果没有则由代理服务器向internet发送访问请求,然后返回web页面时,先缓存起来,然后反馈给客户机. Squid代理的基本类型: 传统代理:普通的代理方式,客户机需手动指定代理地址和工作端口 透明代理:客户机不需要指定代理地址和工作端口,而是通过默认路由,防火

SQUID代理服务(3)

透明代理透明代理提供的服务功能与传统代理是一致的,但是其"透明"的实现依赖于默认路由和防火墙的重定向策略,因此更适用于为局域网主机服务,而不适合为INTERNET中的客户机提供服务.配置SQUID支持透明代理SQUID服务的默认配置并不支持透明代理,因此需要调整相关设置.对于2.6以上版本的SQUID服务,只要在http_port配置行加上一个"transparent"(透明)选项,就可以支持透明代理了. *vim /etc/squid.conf* *httppor