squid 代理服務器功能:
1.正向代理
2.反向代理--web加速
3.實理用戶驗證和訪問控制的功能,與iptables配合使用實理透明代理。
說明:Squid不僅僅支持HTTP協議,而且還支持FTP,GOPHER,SSL和WAIS等協議
一.安裝及文件目錄
1. 默認編譯後安裝的路徑爲/usr/local/squid
下面包含以下文件夾:
bin------包含 了squid默認的啓動腳本
sbin-----squid可執行程序
etc------包含配置文件squid.conf
libexec--包含squid服務器的函數庫
logs-----squid的日誌
man------幫助文件
share----顯示錯誤信息的html頁面
var------包含squid服務器的log,pid,swap等目錄。
/var/cache/squid可以緩存大量的數據。
2. 以rpm文式安裝的,系統會把安裝文件分散到不同的目錄下。
/etc/rc.d/init.d/squid
/usr/lib/squid
/usr/sbin/squid -----squid可執行程序
/etc/squid ----------配置文件
/usr/share/squid
/var/log/squid
/var/spool/squid ---這裏保存緩存文件的地方
查看是否安裝此軟件包:
$rpm -qa|grep -i squid
squid啓動服務
$chkconfig squid on
$service squid start
如果沒有var目錄下沒有cache目錄,則可以執行以下的命令進行初始化,這一步是必須的。
$squid -z #創建 Squid 使用的緩存目錄,在第一次運行 Squid 前必須執行。
或
$/usr/sbin/squid -z
如果需要重建 Squid 緩存,可以先使用 'rm -f /usr/local/squid/cache/*' 刪除緩存,再使用 -z 重建。
二.配置方案
$vi /etc/squid/squid.conf
只要更改/etc/squid/squid.conf文件,執行 $service squid restart就可以生效。
以下爲默認的一些信息,只要把iptables停止掉或在iptables規則裏允許通過就可以使用了squid了,如果要定配一些squid的ACL就可以滿足你的應用需求了。
完成!
--------------------------------------------------------------------------------------
設置iptables 防火牆,加入;
iptables -t nat -A PREROUTING -s 192.168.1.225/32 -p tcp --dport 80 -j REDIRECT –to-ports 3128
端口定義部分:
# TAG: http_port
# Usage: port [options]
# hostname:port [options] //這裏可以用ts3-142:3128
# 1.2.3.4:port [options] //這裏可以用172.16.78.142:3128
http_port 3128
訪問控制列表
# TAG: acl
# Defining an Access List
#
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
# TAG: http_access
# Allowing or Denying access based on defined access lists
#
# Access to the HTTP port:
http_access allow|deny [!]aclname ...
訪問控制
格式:http_access allow/deny aclname
典型訪問控制規則如下:
http_access allow your-aclname
http_access deny all
使用http_access的時候特別要注意的是,Squid將使用allow-deny-allow-deny……這樣的順序套用規則。例如,當一個用戶訪問**服務器時,Squid會順序測試Squid中定義的所有規則列表,當所有規則都不匹配時,Squid會使用與最後一條相反的規則。就像上面這個例子,假設有一個用戶的IP地址是 192.168.0.201,他試圖通過這臺**服務器訪問Internet,會發生什麼情況呢?我們會發現,他能夠正常訪問,因爲Squid找遍所有訪問列表也沒有和192.168.0.201有關的定義,便開始應用規則,而最後一條是deny,那麼Squid默認的下一條處理規則是allow,所以 192.168.0.201反而能夠訪問Internet了,這顯然不是我們希望的。所以在所有squid.conf中,最後一條規則永遠是 http_access deny all,而all就是前面定義的“src 0.0.0.0”。
# ACCESS CONTROLS
# -----------------------------------------------------------------------------
# TAG: acl
# Defining an Access List //定義訪問控制列表
#
# acl aclname acltype string1 ... //訪問控制列表的格式
# acl aclname acltype "file" ...
#
# when using "file", the file should contain one item per line
#
# acltype is one of the types described below
#
# By default, regular expressions are CASE-SENSITIVE. To make
# them case-insensitive, use the -i option.
#
*** IP地址訪問控制列表***
# acl aclname src ip-address/netmask ... (clients IP address) //以源客戶端IP地址爲列表
# acl aclname src addr1-addr2/netmask ... (range of addresses) //以源IP地址範圍爲列表
# acl aclname dst ip-address/netmask ... (URL host's IP address) //以目的主機IP地址爲列表
# acl aclname myip ip-address/netmask ... (local socket IP address) //squid主機的IP地址爲myip列表
#
# acl aclname arp mac-address ... (xx:xx:xx:xx:xx:xx notation)
# # The arp ACL requires the special configure option --enable-arp-acl.
# # Furthermore, the arp ACL code is not portable to all operating systems.
# # It works on Linux, Solaris, FreeBSD and some other *BSD variants.
# #
# # NOTE: Squid can only determine the MAC address for clients that are on
# # the same subnet. If the client is on a different subnet, then Squid cannot
# # find out its MAC address.
#
***域名訪問控制列表***
# acl aclname srcdomain .foo.com ... # reverse lookup, client IP //以域名爲源列表
# acl aclname dstdomain .foo.com ... # Destination server from URL //以域名爲目的列表
# acl aclname srcdom_regex [-i] xxx ... # regex matching client name //
# acl aclname dstdom_regex [-i] xxx ... # regex matching server
# # For dstdomain and dstdom_regex a reverse lookup is tried if a IP
# # based URL is used and no match is found. The name "none" is used
# # if the reverse lookup fails.
#
***時間訪問控制列表***
# acl aclname time [day-abbrevs] [h1:m1-h2:m2]
# day-abbrevs:
# S - Sunday
# M - Monday
# T - Tuesday
# W - Wednesday
# H - Thursday
# F - Friday
# A - Saturday
# h1:m1 must be less than h2:m2
***其它訪問控制列表***
# acl aclname url_regex [-i] ^http:// ... # regex matching on whole URL //匹配以http://開始的列表
# acl aclname urlpath_regex [-i] \.gif$ ... # regex matching on URL path //匹配以.gif爲結尾的列表
# acl aclname urllogin [-i] [^a-zA-Z0-9] ... # regex matching on URL login field //
# acl aclname port 80 70 21 ... //端口列表
# acl aclname port 0-1024 ... # ranges allowed //端口範圍列表
# acl aclname myport 3128 ... # (local socket TCP port) //squid本地端口
# acl aclname proto HTTP FTP ... //協議列表
# acl aclname method GET POST ... //訪問方式列表
# acl aclname browser [-i] regexp ... //瀏覽器列表
squid 代理服務器配置
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
Amoeba for MySQL學習研究之配置
lvrenX
2019-02-24 13:04:33
VMware Tools 安裝、卸載及配置
如沐陽光
2019-02-24 13:00:22
配置基本的邊界網關協議(BGP)
wpgs
2019-02-23 14:05:20
如何備份cisco路由器配置文件
talkstone
2019-02-23 13:59:02
核心網絡設備配置及參數如何備份
talkstone
2019-02-23 13:59:02
交換機的啓動及基本配置
talkstone
2019-02-23 13:59:02
Cisco路由器安全配置必用10條命令
LQ_112
2019-02-23 13:47:18
轉貼:51cto論壇
spirit9
2019-02-23 13:37:48
DNS原理概述及使用(一)
shang61511
2019-02-23 14:04:46
DNS原理概述及使用(二)
shang61511
2019-02-23 14:02:01
在RedHat5中實現透明代理
hkb178149081
2019-02-23 13:53:01
代理服務之正向透明代理
大將軍繼華
2019-02-23 13:37:48
Squid代理服務之普通代理
大將軍繼華
2019-02-23 13:37:43