squide代理
搭建squid服務器
普通代理 : ?客戶端必須在瀏覽器里指定代理服務器的ip地址和代 ? ? ? ? ? ? ? ? ?理服務使用的端口號,才能夠通過代理服務器訪問 ? ? ? ? ? ? ? ? ?公網(wǎng)
mount ?/dev/cdrom ?/mnt
rpm -ivh /mnt/Packages/squid-3.1.10-19.el6_4.x86_64.rpm
默認只代替私網(wǎng)網(wǎng)段主機上網(wǎng)
vim ? /etc/squid/squid.conf
http_port ? 3128
cache_dir ufs /var/spool/squid 100 16 256
cache_mem ?8 MB
:wq
service ?squid restart
訪問日志 ? /var/log/squid/access.log
------------------------------------------------------------------
透明代理 : 客戶端不需要在瀏覽器里指定 代理服務器的ip地址和代理服務使用的端口號;必須把網(wǎng)關(guān)指向代理服務器的內(nèi)網(wǎng)接口的ip地址。
vim /etc/squid/squid.conf
http_port ? 3128 ?transparent
:wq
service ?squid ?restart
service iptables ? start
iptables ?-t ? filter ? -F
iptables ?-t ?nat ?-A ?PREROUTING ?-s 192.168.4.0/24 ?-i ?eth0 ? ?-p ?tcp ? --dport ?80 ? -j ?REDIRECT --to-ports 3128
service ?iptables ?save
客戶端配置 ? route ?add default ?gw ?192.168.4.5
cache_dir ? ? ?100M ? ? ? ? ? ?95M
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?5M
? ? ? ? ? ? ? ? ? ? ? ?90%
? ? ? ? ? ? ? ? ? ? ? ?95%
?74 refresh_pattern ^ftp: ? ? ? ? ? ? ? 1440 ? ?20% ? ? 10080
?75 refresh_pattern ^gopher: ? ? ? ?1440 ? ?0% ? ? ?1440
?76 refresh_pattern -i (/cgi-bin/|\?) ? ? 0 ? ? 0% ? ? ?0
?77 refresh_pattern ?. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?0 ? ? 20% ? ? 4320
-----------------------------------------------------------------
反向代理 ? 代替公網(wǎng)用戶訪問私有網(wǎng)絡
給內(nèi)網(wǎng)網(wǎng)站編寫網(wǎng)頁文件?
echo ? aaaa ? > ?/var/www/htm./a6.html?
service ?iptables ?stop
vim /etc/squid/squid.conf
#http_access deny ?all
http_access ?allow ? all
http_port ? 80 ?vhost
cache_peer ?192.168.4.6 ?parent ? 80 ? 0 ?originserver
#cache_peer ?192.168.4.7 ?parent ? 80 ? 0 ?originserver
:wq
service ?squid restart
客戶端訪問 ?
http://1.1.1.1/a6.html
vim /etc/hosts
1.1.1.1 ? www.tarena.com ? www
1.1.1.1 ? bbs.tarena.com ? bbs
:wq
--------------------------------------------------
內(nèi)網(wǎng)網(wǎng)站服務器是基于域名的虛擬主機
? 123 ?mkdir /wwwdir ?/bbsdir
? 126 ?echo ?wwwpage ?> /wwwdir/index.html
? 127 ?echo ?bbspage ?> /bbsdir/index.html
[root@pc6 html]# tail -15 ?/etc/httpd/conf/httpd.conf?
NameVirtualHost *:80
<VirtualHost *:80>
? ? DocumentRoot /wwwdir
? ? ServerName www.tarena.com
? ? ErrorLog logs/www.tarena.com-error_log
? ? CustomLog logs/www.tarena.com-access_log common
</VirtualHost>
<VirtualHost *:80>
? ? DocumentRoot /bbsdir
? ? ServerName bbs.tarena.com
? ? ErrorLog logs/bbs.tarena.com-error_log
? ? CustomLog logs/bbs.tarena.com-access_log common
</VirtualHost>
[root@pc6 html]#?
129 ?service httpd restart
客戶在訪問不同主機名時出現(xiàn)不同的頁面內(nèi)容
vim /etc/hosts
1.1.1.1 www.tarena.com ? www
1.1.1.1 bbs.tarena.com ? bbs
:wq
訪問
http://www.tarena.com ??
http://bbs.tarena.com ? ? ??
-----------------------------------------------------------------
內(nèi)網(wǎng)網(wǎng)站服務 機基于端口的虛擬主機
? ? /wwwdir ? ? ? 80
? ? /bbsdir ? ? ? ? ?8080
vim ?httpd.conf
<VirtualHost *:80>
? ? DocumentRoot /wwwdir
? ? ErrorLog logs/www.tarena.com-error_log
? ? CustomLog logs/www.tarena.com-access_log common
</VirtualHost>
listen 8080
<VirtualHost *:8080>
? ? DocumentRoot /bbsdir
? ? ErrorLog logs/bbs.tarena.com-error_log
? ? CustomLog logs/bbs.tarena.com-access_log common
</VirtualHost>
service ? httpd ?restart
代理服務器的配置?
vim ?squid.conf
http_port ? 80 ?vhost
cache_peer ?192.168.4.6 ?parent ? 80 ? 0 ?originserver ?name=www
cache_peer ?192.168.4.6 ?parent ? 8080 ? 0 ?originserver ?name=bbs
cache_peer_domain ?www ?www.tarena.com
cache_peer_domain ?bbs ?bbs.tarena.com
:wq
rm ?-rf ? /var/spool/squid/*
service ?squid ?stop
service ?squid ?start
客戶端在訪問代理時 可以訪問到對應的網(wǎng)頁文件
cat ?/etc/hosts
1.1.1.1 ? www.tarena.com ? www
1.1.1.1 ? bbs.tarena.com ? ? ?bbs
http://1.1.1.1
http://www.tarena.com ? ? ? ? -> ?/wwwdir ? ? ? 80
http://bbs.tarena.com ? ? ? ? ? ?-> ?/bbsdir ? ? ? ? ?8080
------------------------------------------------------------------
普通代理?
透明代理
反向代理
------------------------------------------------------------------
ACL訪問控制列表(透明代理)
限制客戶端可以通過自己訪問什么樣的網(wǎng)絡資源。
定義acl ? (squid.conf)
acl ?名稱 ? 類型 ? ?值
src ? ?源地址dst ? ?目標地址port ? ?目標端口
dstdomain ? ?目標域
time ? ?訪問時間
maxconn ? ?最大并發(fā)連接
url_regex ? ?目標URL地址
urlpath_regex ? ?整個目標URL路徑
acl ?LAN1 src ?192.168.1.0/24
acl ?PC1 src ?192.168.1.66/32
acl ?Blk _ Domain dstdomain ? .qq.com .kaixin001.com
acl ?Work _Hours ?time MTWHF ?08:30-17:30
acl ?Max20_Conn maxconn ?20
acl ?Blk_URL ?url_regex ? -i ?^rtsp:// ?^mms://
acl ?Blk_Words ?urlpath_regex -i ?sex ?adult
acl ?RealFile ? ?urlpath_regex ?-i ? \.rmvb$ ?\.rm$ ?\.mp3$
調(diào)用acl
http_access ? ?allow/deny ? acl名稱列表
http_access deny ?LAN1 ? Blk_URL
http_access deny ?LAN1 ? Blk_Words
http_access deny ?PC1 ? ? ?RealFilehttp_access deny ?PC1 ? Max20_Connhttp_access allow ?LAN1 ? Work_Hours
轉(zhuǎn)載于:https://blog.51cto.com/10949891/1738229
總結(jié)
- 上一篇: 【IOS学习基础】OC类的相关
- 下一篇: [python]pythonic的字典常