SlideShare a Scribd company logo
1 of 37
Download to read offline
Proxy Server
โดย… อดิศร ขาวสังข
ทดสอบบน Fedora Core4
Proxy Server
เปน Server ที่ทําหนาที่เปนตัวแทนหรือตัวกลาง นั่นคือ Proxy จะทํา
หนาที่แทน Client ในการติดตอกับ Server ตัวอื่น ๆ หรือเปนสื่อกลาง
(Mediator) สําหรับ Computer Communications
อาจะเรียกวาเปนการทํา Web Caching คือทําหนาที่เก็บขอมูลเว็บเพจที่
Client เคยเรียกใชงานไวในฮารดดิสก เพื่อเพิ่มความเร็วในการเรียกดู
เว็บของเครื่อง Client ในครั้งตอไป แตเมื่อ Client เรียกใชงานแลวไมมี
ขอมูลในฮารดดิสก ตัว Proxy Server จะทําหนาที่แทนคือไปโหลด
ขอมูลจากอินเตอรเน็ตแลวสงตอใหกับ Client พรอมกับสําเนาขอมูลเก็บ
ไว
การใชงาน Proxy Server ชวยใหประหยัด IP จริง (Registered IP) ได
ลักษณะการใชงาน Proxy Server
ทําหนาที่เปน Caching อยางเดียว
เปนทั้ง Caching + Gateway เมื่อติดตั้ง Network Card บน
Proxy Server มากกวา 1 การด และประยุกตคําสั่ง iptables เขา
ไปก็จะสามารถทําให Proxy Server เปน Gateway ที่ควบคุมการ
ติดตอระหวางเครือขายที่ตาง Network กันได ซึ่งสามารถที่จะ
เพิ่มฟงกชันของ Firewall เขาไปไดดวย
Proxy Server ที่เปน Caching
PC
PC
PC
Router Switch
Proxy Server
Modem
202.129.16.238 202.129.48.1
202.129.48.2
202.129.48.10
202.129.48.11
202.129.48.12
Dedicated Line to ISP
EthernetSerial
Proxy Server ที่เปนทั้ง Caching + Gateway
PC PC
PC
Router
Switch
Proxy + Gateway
Server
Modem
202.129.16.238 202.129.48.1
202.129.48.2
Dedicated Line to ISP
EthernetSerial
Switch
202.129.48.5
192.168.1.1
192.168.1.11
192.168.1.12
192.168.1.13
Web Server
Ftp Server
Mail Server
202.129.48.6
202.129.48.7
202.129.48.8
202.129.16.236/30 202.129.48.0/30
202.129.48.4/29
192.168.1.0/24
ความสามารถเพิ่มเติมของ Proxy Server
Access List (ACL)
– กําหนดวันเวลาในการใชงาน
– กรองเว็บไซตที่ไมพึงประสงค
– หาม IP หรือ Network ใด ๆ ใชงาน
Transparent Proxy คือการใชงาน Internet โดยที่เครื่อง Client
ไมตองระบุ IP ของ Proxy Server
การตรวจสอบและติดตั้ง Squid ผาน shell prompt
โปรแกรม squid จะอยูแผนที่ 1 ของ FC4
การติดตั้ง squid ผาน GUI (Package Management)
ติดตั้งจากเมนู Desktop System Settings Add/Remove Applications
– อยูที่รายการ Servers Web Server
การคอนฟก Squid ขั้นตน
แกไข Config File ที่ /etc/squid/squid.conf ดังนี้
– ใหเอาเครื่องหมาย # หนาคําวา acl our_network src ออก และใสคา
Network ที่จะอนุญาตใหใชงาน Squid ไดเขาไป
– เอาเครื่องหมาย # หนา http_access allow our_networks ออก
การ Start Squid
Start จากเมนู Service
Desktop System Settings ServerSettings Services
Start จาก shell prompt
service squid start/stop/restart
/etc/init.d/squid start/stop/restart
/etc/init.d/ link ไปยัง /etc/rc.d/init.d
การ Start Squid (ตอ)
• เมื่อมีปญหาไมสามารถ start squid ไดใหใสชื่อ hostname ในที่หัวขอ
visible_hostname ในไฟล /etc/squid/squid.conf ดังตัวอยาง
การ Start Squid (ตอ)
แลว start อีกครั้ง
คือวิธีการที่ทําใหผูใชงานไมตองมีการกําหนดการใชงานที่ browser วาจะ
ใหใชงานผาน Proxy Server ตัวไหน
นั่นคือเมื่อ Packet ขอมูลวิ่งผาน gateway ตัว gateway จะคอยตรวจจับดู
วา Packet ขอมูลที่วิ่งผานเปน http (TCP 80) หรือไม ถาเปน http ก็จะ
บังคับให Packet ขอมูลดังกลาววิ่งผานไปยัง Proxy Server ดวยการระบุ
IP ของ Proxy Server และระบุพอรตของ Proxy Server (เชน 3128)
ที่ Proxy Server จะตองมีการคอนฟกเพิ่มเติมในสวนของ Squid ให
รองรับการทํางานแบบ Transparent Proxy
Transparent Proxy บน Linux
ขั้นตอนการทํา Transparent Proxy
1. ใชคําสั่ง iptables เพื่อทําการตรวจสอบ Packet ที่วิ่งผาน Gateway ถาเปน
การเรียกใชงาน http ใหทําการ Redirect ไปยัง Proxy Server ดังนี้
กรณี Gateway เปนคนละเครื่องกับ Proxy Server
iptables -t nat -A PREROUTING -p tcp -i eth1 -s 192.168.1.0/24 -d !
203.146.55.131 --dport 80 -j DNAT -- to-dest 203.146.55.132:3128
กรณี Gateway กับ Proxy Server อยูบนเครื่องเดียวกัน
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 80 -j REDIRECT --to-port
3128
กรณี Gateway เปนคนละเครื่องกับ Proxy Server
กรณี Gateway กับ Proxy Server อยูบนเครื่องเดียวกัน
ขั้นตอนการทํา Transparent Proxy (ตอ)
2. ใหทําการคอนฟก Proxy Server (Squid) ใหรองรับ Transparent Proxy
ดวยการใหมีคาตอไปนี้อยูในไฟลคอนฟก
httpd_accel_port 80
httpd_accel_host virtual
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
หมายเหตุ ในกรณีที่ gateway ไมใช Linux Server เชนอาจเปน Router ทั่วไป
ก็ตองมีการคอนฟก Router ดังกลาวคอยตรวจจับ Packet ที่เปน http และมี
การบังคับให Redirect ไปยัง Proxy Server เชนกัน
ขอควรพิจารณาในการทํา Transparent Proxy
การทํา Transparent Proxy ตองมีการเซ็ตคา DNS ใหกับเครื่อง Client ดวย (ทั้ง ๆ ที่
การใชงาน Proxy Server แบบกําหนดคา Server เองไมตองกําหนดคา DNS Server
ใหกับเครื่อง Client ก็ได)
ถาเครื่อง Client ชี้ DNS Server ไปยังเครือขายภายนอก จะตองมีการทํา Outbound
NAT ดวย
ในกรณีทีตองการให Client สามารถใชบริการอื่น ๆ ที่นอกเหนือจากเว็บควรจะทํา
Outbound NAT + Transparent Proxy
การทํา Outbound NAT + Transparent Proxy ถา Proxy เกิด down ก็ไมสามารถใช
งานเว็บไดเพราะถูกบังคับดวยคําสั่ง iptables โดยไมสนใจวา squid จําทํางานอยู
หรือไม
การตรวจสอบการใชงาน Proxy Server
สามารถตรวจสอบการใชงาน Squid Proxy ไดที่ cache_access_log
ของ Squid ซึ่งคา Default จะอยูที่ /var/log/squid/access.log เปน
ไฟลที่เก็บขอมูล web site ที่ client รองขอ
โดยการตรวจสอบใหใชคําสั่ง tail ดังนี้
tail –f /var/log/squid/access.log
และในตําแหนงนี้จะมี log file อีก 2 ไฟลคือ
/var/log/squid/cache.log เก็บขอมูลทั่วไปเกี่ยวกับ your cache’s
behavior
/var/log/squid/store.log //show which objects are ejected from the
cache, and which objects are saved and for how long
ตัวอยางการใชคําสั่ง tail –f /var/log/squid/access.log
ความหมายจากไฟล access.log
TCP_MISS : ขอมูลของเว็บไซตนี้ยังไมมีใน cache พร็อกซี่ตองไป GET
ขอมูลจาก Web Site ปลายทาง
SINGLE_PAREN : กําลังมีการสงขอมูลไปยัง Parent Proxy
TCP_CLIENT_REFRESH_MIS
TCP_IMS_HIT : Proxy ตองอัพเดตขอมูลใหม ถามีการ
refresh ขอมูลที่ client ตัว Proxy จะทํา
การโหลดขอมูลใหมจากเว็บไซตทันที
TCP_MEM_HIT
TCP_HIT : มีขอมูลของเว็บไซตนี้ใน cache พร็อกซี่ไมตองไป
ดาวนโหลดหรือ GET ขอมูลจากเว็บปลายทาง
การทํา Access Control Lists บน Squid
You can limit users' ability to browse the Internet with access control
lists (ACLs).
Each ACL line defines a particular type of activity, such as an access
time or source network, they are then linked to an http_access
statement that tells Squid whether or not to deny or allow traffic that
matches the ACL.
Squid matches each Web access request it receives by checking the
http_access list from top to bottom. If it finds a match, it enforces
the allow or deny statement and stops reading further.
The final http_access statement denies everything, so it is best to place
new http_access statements above it
The very last http_access statement in the squid.conf file denies all access.
You therefore have to add your specific permit statements above this line.
In the course’s examples, I've suggested that you place your statements at
the top of the http_access list for the sake of manageability, but you can
put them anywhere in the section above that last line.
Squid has a minimum required set of ACL statements in the
ACCESS_CONTROL section of the squid.conf file. It is best to put new
customized entries right after this list to make the file easier to read.
การทํา Access Control Lists บน Squid (ตอ)
การทํา Access Control Lists (ACLs)
1. สรางกฏของ access list ไวในตําแหนง ACLs ของไฟลคอนฟก
(/etc/squid/squid.conf) โดยควรวางไวบนบรรทัด acl our_network เชน
• acl ban_dst_domain dstdom_regex thumbnow.com japangirl.com
newpicpost.com
2. นํากฏไปใชงานดวยการใชคําสั่ง http_access ไวหลังกฏในขอ 1 เชน
• http_access deny ban_dst_domain
หมายเหตุ : ถาวางคําสั่งทั้งสองไวลางบรรทัด acl our_network จะไมมีผลตอ
Access Control
ขั้นตอนการทํา Access Control Lists
ตัวอยางการทํา Access Control Lists
ตัวอยางการบล็อก IP ตนทาง
– acl ban_src_ip src 192.168.1.1/255.555.255.255
– http_access deny ban_src_ip
ตัวอยางการบล็อกโดเมนปลายทาง
– acl ban_dst_domain dstdom_regex thumbnow.com japangirl.com หรือ
acl ban_dst_domain dstdomain .thumbnow.com .japangirl.com
– http_access deny ban_dst_domain
ตัวอยางการบล็อก url ที่เปนคํา/วลี
– acl ban_word url_regex nude sucker porn
– http_access deny ban_word
ตัวอยางการทํา Access Control Lists (ตอ)
ตัวอยางการบล็อกโดเมนปลายทางโดยเก็บชื่อโดเมนเปนไฟลไว
– acl ban_dst_domain dstdom_regex ‘/etc/squid/ban_dst_dommain’
– http_access deny ban_dst_domain
ตัวอยางการบล็อก url ที่เปนคํา/วลี โดยเก็บคํา/วลี ไวในไฟล
– acl ban_word url_regex ‘/etc/squid/ban_word’
– http_access deny ban_word
ขอมูลในไฟลอาจเปนดังรูป
Restricting Web Access By Time
•You can create access control lists with time parameters. For
example, you can allow only business hour access from the home
network.
# Add this to the bottom of the ACL section of squid.conf
acl home_network src 192.168.1.0/24
acl business_hours time M T W H F 9:00-17:00
# Add this at the top of the http_access section of squid.conf
http_access allow home_network business_hours
Restricting Web Access By Time (Cont.)
•Or, you can allow morning access only:
# Add this to the bottom of the ACL section of squid.conf
acl mornings time 08:00-12:00
# Add this at the top of the http_access section of squid.conf
http_access allow mornings
Password Authentication Using NCSA
Password Authentication Using NCSA
การสราง web page เพื่อแจงเตือนสําหรับ web ตองหาม
สรางขอความเตือนในรูปแบบ HTML จาก Editor หรือ
โปรแกรมสําหรับสราง Web page
นําไฟลที่สรางเสร็จไปทับไฟลที่
/etc/squid/errors/ERR_ACCESS_DENIED
Multi-Level Web Caching
Multi-Level Web Caching (ตอ)
Proxy 2
Proxy 1
Proxy 3
Proxy
การทํา Cache Peer
แบบ parent
• A parent cache can get documents from another cache
higher in the hierarchy or from the source, depending
whether it has more parent or neighbor caches in its level.
A parent cache should be used when there are no more
opportunities to get the document from a cache on the
same level.
แบบ sibling
• A neighbor (or sibling) cache is one that serves only
documents it already has.
ตัวอยางการทํา Cache Peer
• ทําไดดวยการคอนฟกในไฟล /etc/squid/squid.conf ซึ่งมีรูปแบบดังนี้
cache_peer hostname type http_port icp_port เชน
cache_peer parent.foo.net parent 3128 3130 [proxy-only]
cache_peer sib1.foo.net sibling 3128 3130 [proxy-only]
cache_peer sib2.foo.net sibling 3128 3130 [proxy-only]
• [proxy-only] : to specify that objects fecthed from this cache
should not be saved locally
• เครื่องที่เปน parent หรือ sibling ตองอนุญาตใหทํา cache_peer ดวย
การเปดพอรต icp_port เปน 3130 (default) ถาไมอนุญาตใหกําหนด
icp_port เปน 0
Reverse Proxy Server
Reverse Proxy Server (ตอ)
• In reverse proxy mode, the proxy server functions more like a web server
with respect to the clients it services. Unlike internal clients, external clients
are not preconfigured to access the proxy server. Instead, the site URL
routes the client to the proxy as if it were a web server. Replicated content is
delivered from the proxy cache to the external client without exposing the
origin server or the private network residing safely behind the firewall.
Multiple reverse proxy servers can be used to balance the load on an over-
taxed web server in much the same way.
• Reverse proxy servers are commonly used for secure web publishing.
Having a proxy server accepting and filling outside requests allows you to
keep your web server behind the firewall. You can then use the web server
as a protected web site, staging documents for testing before they are
published externally. When you are ready, you can publish selected content
to the reverse proxy server's cache.

More Related Content

Similar to Proxy fc4 web

การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 05
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 05การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 05
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 05Jenchoke Tachagomain
 
การใช้เครื่องมือต่างๆ1
การใช้เครื่องมือต่างๆ1การใช้เครื่องมือต่างๆ1
การใช้เครื่องมือต่างๆ1guestdfabcfa
 
การใช้เครื่องมือต่างๆ
การใช้เครื่องมือต่างๆการใช้เครื่องมือต่างๆ
การใช้เครื่องมือต่างๆguest3f77f6
 
การใช้เครื่องมือต่างๆ1
การใช้เครื่องมือต่างๆ1การใช้เครื่องมือต่างๆ1
การใช้เครื่องมือต่างๆ1guestdfabcfa
 
การใช้เครื่องมือต่างๆ
การใช้เครื่องมือต่างๆการใช้เครื่องมือต่างๆ
การใช้เครื่องมือต่างๆguest3f77f6
 
การใช้เครื่องมือต่างๆ12
การใช้เครื่องมือต่างๆ12การใช้เครื่องมือต่างๆ12
การใช้เครื่องมือต่างๆ12guest7878b9
 
Android Control Hardware and Arduino IoT ( 22 Aug 15 )
Android Control Hardware and Arduino IoT ( 22 Aug 15 )Android Control Hardware and Arduino IoT ( 22 Aug 15 )
Android Control Hardware and Arduino IoT ( 22 Aug 15 )Adun Nanthakaew
 
Basic linux
Basic linuxBasic linux
Basic linuxtaggi
 
Basic Linux
Basic LinuxBasic Linux
Basic Linuxminafaw2
 
คู่มือการสร้างเว็บDreammx2004
คู่มือการสร้างเว็บDreammx2004คู่มือการสร้างเว็บDreammx2004
คู่มือการสร้างเว็บDreammx2004kernger99
 
ตัวอย่างบทที่3โปรแกรม filter บน linux
ตัวอย่างบทที่3โปรแกรม filter บน linuxตัวอย่างบทที่3โปรแกรม filter บน linux
ตัวอย่างบทที่3โปรแกรม filter บน linuxrubtumproject.com
 

Similar to Proxy fc4 web (20)

การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 05
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 05การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 05
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 05
 
Cent os
Cent osCent os
Cent os
 
NETWORK SERVICEOPENSSH + NTP + SQUID
NETWORK SERVICEOPENSSH + NTP + SQUIDNETWORK SERVICEOPENSSH + NTP + SQUID
NETWORK SERVICEOPENSSH + NTP + SQUID
 
Kafka for developer
Kafka for developerKafka for developer
Kafka for developer
 
การใช้เครื่องมือต่างๆ1
การใช้เครื่องมือต่างๆ1การใช้เครื่องมือต่างๆ1
การใช้เครื่องมือต่างๆ1
 
การใช้เครื่องมือต่างๆ
การใช้เครื่องมือต่างๆการใช้เครื่องมือต่างๆ
การใช้เครื่องมือต่างๆ
 
การใช้เครื่องมือต่างๆ1
การใช้เครื่องมือต่างๆ1การใช้เครื่องมือต่างๆ1
การใช้เครื่องมือต่างๆ1
 
การใช้เครื่องมือต่างๆ
การใช้เครื่องมือต่างๆการใช้เครื่องมือต่างๆ
การใช้เครื่องมือต่างๆ
 
การใช้เครื่องมือต่างๆ12
การใช้เครื่องมือต่างๆ12การใช้เครื่องมือต่างๆ12
การใช้เครื่องมือต่างๆ12
 
Docker 1st time
Docker 1st timeDocker 1st time
Docker 1st time
 
Greenstone Installation
Greenstone InstallationGreenstone Installation
Greenstone Installation
 
Android Control Hardware and Arduino IoT ( 22 Aug 15 )
Android Control Hardware and Arduino IoT ( 22 Aug 15 )Android Control Hardware and Arduino IoT ( 22 Aug 15 )
Android Control Hardware and Arduino IoT ( 22 Aug 15 )
 
Basic linux
Basic linuxBasic linux
Basic linux
 
Basic Linux
Basic LinuxBasic Linux
Basic Linux
 
php5new
php5newphp5new
php5new
 
Basic Kong API Gateway
Basic Kong API GatewayBasic Kong API Gateway
Basic Kong API Gateway
 
คู่มือการสร้างเว็บDreammx2004
คู่มือการสร้างเว็บDreammx2004คู่มือการสร้างเว็บDreammx2004
คู่มือการสร้างเว็บDreammx2004
 
ตัวอย่างบทที่3โปรแกรม filter บน linux
ตัวอย่างบทที่3โปรแกรม filter บน linuxตัวอย่างบทที่3โปรแกรม filter บน linux
ตัวอย่างบทที่3โปรแกรม filter บน linux
 
Firewall
FirewallFirewall
Firewall
 
Red5 workshop
Red5 workshopRed5 workshop
Red5 workshop
 

Proxy fc4 web

  • 1. Proxy Server โดย… อดิศร ขาวสังข ทดสอบบน Fedora Core4
  • 2. Proxy Server เปน Server ที่ทําหนาที่เปนตัวแทนหรือตัวกลาง นั่นคือ Proxy จะทํา หนาที่แทน Client ในการติดตอกับ Server ตัวอื่น ๆ หรือเปนสื่อกลาง (Mediator) สําหรับ Computer Communications อาจะเรียกวาเปนการทํา Web Caching คือทําหนาที่เก็บขอมูลเว็บเพจที่ Client เคยเรียกใชงานไวในฮารดดิสก เพื่อเพิ่มความเร็วในการเรียกดู เว็บของเครื่อง Client ในครั้งตอไป แตเมื่อ Client เรียกใชงานแลวไมมี ขอมูลในฮารดดิสก ตัว Proxy Server จะทําหนาที่แทนคือไปโหลด ขอมูลจากอินเตอรเน็ตแลวสงตอใหกับ Client พรอมกับสําเนาขอมูลเก็บ ไว การใชงาน Proxy Server ชวยใหประหยัด IP จริง (Registered IP) ได
  • 3. ลักษณะการใชงาน Proxy Server ทําหนาที่เปน Caching อยางเดียว เปนทั้ง Caching + Gateway เมื่อติดตั้ง Network Card บน Proxy Server มากกวา 1 การด และประยุกตคําสั่ง iptables เขา ไปก็จะสามารถทําให Proxy Server เปน Gateway ที่ควบคุมการ ติดตอระหวางเครือขายที่ตาง Network กันได ซึ่งสามารถที่จะ เพิ่มฟงกชันของ Firewall เขาไปไดดวย
  • 4. Proxy Server ที่เปน Caching PC PC PC Router Switch Proxy Server Modem 202.129.16.238 202.129.48.1 202.129.48.2 202.129.48.10 202.129.48.11 202.129.48.12 Dedicated Line to ISP EthernetSerial
  • 5. Proxy Server ที่เปนทั้ง Caching + Gateway PC PC PC Router Switch Proxy + Gateway Server Modem 202.129.16.238 202.129.48.1 202.129.48.2 Dedicated Line to ISP EthernetSerial Switch 202.129.48.5 192.168.1.1 192.168.1.11 192.168.1.12 192.168.1.13 Web Server Ftp Server Mail Server 202.129.48.6 202.129.48.7 202.129.48.8 202.129.16.236/30 202.129.48.0/30 202.129.48.4/29 192.168.1.0/24
  • 6. ความสามารถเพิ่มเติมของ Proxy Server Access List (ACL) – กําหนดวันเวลาในการใชงาน – กรองเว็บไซตที่ไมพึงประสงค – หาม IP หรือ Network ใด ๆ ใชงาน Transparent Proxy คือการใชงาน Internet โดยที่เครื่อง Client ไมตองระบุ IP ของ Proxy Server
  • 7. การตรวจสอบและติดตั้ง Squid ผาน shell prompt โปรแกรม squid จะอยูแผนที่ 1 ของ FC4
  • 8. การติดตั้ง squid ผาน GUI (Package Management) ติดตั้งจากเมนู Desktop System Settings Add/Remove Applications – อยูที่รายการ Servers Web Server
  • 9. การคอนฟก Squid ขั้นตน แกไข Config File ที่ /etc/squid/squid.conf ดังนี้ – ใหเอาเครื่องหมาย # หนาคําวา acl our_network src ออก และใสคา Network ที่จะอนุญาตใหใชงาน Squid ไดเขาไป – เอาเครื่องหมาย # หนา http_access allow our_networks ออก
  • 10. การ Start Squid Start จากเมนู Service Desktop System Settings ServerSettings Services Start จาก shell prompt service squid start/stop/restart /etc/init.d/squid start/stop/restart /etc/init.d/ link ไปยัง /etc/rc.d/init.d
  • 11. การ Start Squid (ตอ) • เมื่อมีปญหาไมสามารถ start squid ไดใหใสชื่อ hostname ในที่หัวขอ visible_hostname ในไฟล /etc/squid/squid.conf ดังตัวอยาง
  • 12. การ Start Squid (ตอ) แลว start อีกครั้ง
  • 13. คือวิธีการที่ทําใหผูใชงานไมตองมีการกําหนดการใชงานที่ browser วาจะ ใหใชงานผาน Proxy Server ตัวไหน นั่นคือเมื่อ Packet ขอมูลวิ่งผาน gateway ตัว gateway จะคอยตรวจจับดู วา Packet ขอมูลที่วิ่งผานเปน http (TCP 80) หรือไม ถาเปน http ก็จะ บังคับให Packet ขอมูลดังกลาววิ่งผานไปยัง Proxy Server ดวยการระบุ IP ของ Proxy Server และระบุพอรตของ Proxy Server (เชน 3128) ที่ Proxy Server จะตองมีการคอนฟกเพิ่มเติมในสวนของ Squid ให รองรับการทํางานแบบ Transparent Proxy Transparent Proxy บน Linux
  • 14. ขั้นตอนการทํา Transparent Proxy 1. ใชคําสั่ง iptables เพื่อทําการตรวจสอบ Packet ที่วิ่งผาน Gateway ถาเปน การเรียกใชงาน http ใหทําการ Redirect ไปยัง Proxy Server ดังนี้ กรณี Gateway เปนคนละเครื่องกับ Proxy Server iptables -t nat -A PREROUTING -p tcp -i eth1 -s 192.168.1.0/24 -d ! 203.146.55.131 --dport 80 -j DNAT -- to-dest 203.146.55.132:3128 กรณี Gateway กับ Proxy Server อยูบนเครื่องเดียวกัน iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 80 -j REDIRECT --to-port 3128
  • 16. กรณี Gateway กับ Proxy Server อยูบนเครื่องเดียวกัน
  • 17. ขั้นตอนการทํา Transparent Proxy (ตอ) 2. ใหทําการคอนฟก Proxy Server (Squid) ใหรองรับ Transparent Proxy ดวยการใหมีคาตอไปนี้อยูในไฟลคอนฟก httpd_accel_port 80 httpd_accel_host virtual httpd_accel_with_proxy on httpd_accel_uses_host_header on หมายเหตุ ในกรณีที่ gateway ไมใช Linux Server เชนอาจเปน Router ทั่วไป ก็ตองมีการคอนฟก Router ดังกลาวคอยตรวจจับ Packet ที่เปน http และมี การบังคับให Redirect ไปยัง Proxy Server เชนกัน
  • 18. ขอควรพิจารณาในการทํา Transparent Proxy การทํา Transparent Proxy ตองมีการเซ็ตคา DNS ใหกับเครื่อง Client ดวย (ทั้ง ๆ ที่ การใชงาน Proxy Server แบบกําหนดคา Server เองไมตองกําหนดคา DNS Server ใหกับเครื่อง Client ก็ได) ถาเครื่อง Client ชี้ DNS Server ไปยังเครือขายภายนอก จะตองมีการทํา Outbound NAT ดวย ในกรณีทีตองการให Client สามารถใชบริการอื่น ๆ ที่นอกเหนือจากเว็บควรจะทํา Outbound NAT + Transparent Proxy การทํา Outbound NAT + Transparent Proxy ถา Proxy เกิด down ก็ไมสามารถใช งานเว็บไดเพราะถูกบังคับดวยคําสั่ง iptables โดยไมสนใจวา squid จําทํางานอยู หรือไม
  • 19. การตรวจสอบการใชงาน Proxy Server สามารถตรวจสอบการใชงาน Squid Proxy ไดที่ cache_access_log ของ Squid ซึ่งคา Default จะอยูที่ /var/log/squid/access.log เปน ไฟลที่เก็บขอมูล web site ที่ client รองขอ โดยการตรวจสอบใหใชคําสั่ง tail ดังนี้ tail –f /var/log/squid/access.log และในตําแหนงนี้จะมี log file อีก 2 ไฟลคือ /var/log/squid/cache.log เก็บขอมูลทั่วไปเกี่ยวกับ your cache’s behavior /var/log/squid/store.log //show which objects are ejected from the cache, and which objects are saved and for how long
  • 21. ความหมายจากไฟล access.log TCP_MISS : ขอมูลของเว็บไซตนี้ยังไมมีใน cache พร็อกซี่ตองไป GET ขอมูลจาก Web Site ปลายทาง SINGLE_PAREN : กําลังมีการสงขอมูลไปยัง Parent Proxy TCP_CLIENT_REFRESH_MIS TCP_IMS_HIT : Proxy ตองอัพเดตขอมูลใหม ถามีการ refresh ขอมูลที่ client ตัว Proxy จะทํา การโหลดขอมูลใหมจากเว็บไซตทันที TCP_MEM_HIT TCP_HIT : มีขอมูลของเว็บไซตนี้ใน cache พร็อกซี่ไมตองไป ดาวนโหลดหรือ GET ขอมูลจากเว็บปลายทาง
  • 22. การทํา Access Control Lists บน Squid You can limit users' ability to browse the Internet with access control lists (ACLs). Each ACL line defines a particular type of activity, such as an access time or source network, they are then linked to an http_access statement that tells Squid whether or not to deny or allow traffic that matches the ACL. Squid matches each Web access request it receives by checking the http_access list from top to bottom. If it finds a match, it enforces the allow or deny statement and stops reading further.
  • 23. The final http_access statement denies everything, so it is best to place new http_access statements above it The very last http_access statement in the squid.conf file denies all access. You therefore have to add your specific permit statements above this line. In the course’s examples, I've suggested that you place your statements at the top of the http_access list for the sake of manageability, but you can put them anywhere in the section above that last line. Squid has a minimum required set of ACL statements in the ACCESS_CONTROL section of the squid.conf file. It is best to put new customized entries right after this list to make the file easier to read. การทํา Access Control Lists บน Squid (ตอ)
  • 25. 1. สรางกฏของ access list ไวในตําแหนง ACLs ของไฟลคอนฟก (/etc/squid/squid.conf) โดยควรวางไวบนบรรทัด acl our_network เชน • acl ban_dst_domain dstdom_regex thumbnow.com japangirl.com newpicpost.com 2. นํากฏไปใชงานดวยการใชคําสั่ง http_access ไวหลังกฏในขอ 1 เชน • http_access deny ban_dst_domain หมายเหตุ : ถาวางคําสั่งทั้งสองไวลางบรรทัด acl our_network จะไมมีผลตอ Access Control ขั้นตอนการทํา Access Control Lists
  • 26. ตัวอยางการทํา Access Control Lists ตัวอยางการบล็อก IP ตนทาง – acl ban_src_ip src 192.168.1.1/255.555.255.255 – http_access deny ban_src_ip ตัวอยางการบล็อกโดเมนปลายทาง – acl ban_dst_domain dstdom_regex thumbnow.com japangirl.com หรือ acl ban_dst_domain dstdomain .thumbnow.com .japangirl.com – http_access deny ban_dst_domain ตัวอยางการบล็อก url ที่เปนคํา/วลี – acl ban_word url_regex nude sucker porn – http_access deny ban_word
  • 27. ตัวอยางการทํา Access Control Lists (ตอ) ตัวอยางการบล็อกโดเมนปลายทางโดยเก็บชื่อโดเมนเปนไฟลไว – acl ban_dst_domain dstdom_regex ‘/etc/squid/ban_dst_dommain’ – http_access deny ban_dst_domain ตัวอยางการบล็อก url ที่เปนคํา/วลี โดยเก็บคํา/วลี ไวในไฟล – acl ban_word url_regex ‘/etc/squid/ban_word’ – http_access deny ban_word ขอมูลในไฟลอาจเปนดังรูป
  • 28. Restricting Web Access By Time •You can create access control lists with time parameters. For example, you can allow only business hour access from the home network. # Add this to the bottom of the ACL section of squid.conf acl home_network src 192.168.1.0/24 acl business_hours time M T W H F 9:00-17:00 # Add this at the top of the http_access section of squid.conf http_access allow home_network business_hours
  • 29. Restricting Web Access By Time (Cont.) •Or, you can allow morning access only: # Add this to the bottom of the ACL section of squid.conf acl mornings time 08:00-12:00 # Add this at the top of the http_access section of squid.conf http_access allow mornings
  • 30. Password Authentication Using NCSA Password Authentication Using NCSA
  • 31. การสราง web page เพื่อแจงเตือนสําหรับ web ตองหาม สรางขอความเตือนในรูปแบบ HTML จาก Editor หรือ โปรแกรมสําหรับสราง Web page นําไฟลที่สรางเสร็จไปทับไฟลที่ /etc/squid/errors/ERR_ACCESS_DENIED
  • 33. Multi-Level Web Caching (ตอ) Proxy 2 Proxy 1 Proxy 3 Proxy
  • 34. การทํา Cache Peer แบบ parent • A parent cache can get documents from another cache higher in the hierarchy or from the source, depending whether it has more parent or neighbor caches in its level. A parent cache should be used when there are no more opportunities to get the document from a cache on the same level. แบบ sibling • A neighbor (or sibling) cache is one that serves only documents it already has.
  • 35. ตัวอยางการทํา Cache Peer • ทําไดดวยการคอนฟกในไฟล /etc/squid/squid.conf ซึ่งมีรูปแบบดังนี้ cache_peer hostname type http_port icp_port เชน cache_peer parent.foo.net parent 3128 3130 [proxy-only] cache_peer sib1.foo.net sibling 3128 3130 [proxy-only] cache_peer sib2.foo.net sibling 3128 3130 [proxy-only] • [proxy-only] : to specify that objects fecthed from this cache should not be saved locally • เครื่องที่เปน parent หรือ sibling ตองอนุญาตใหทํา cache_peer ดวย การเปดพอรต icp_port เปน 3130 (default) ถาไมอนุญาตใหกําหนด icp_port เปน 0
  • 37. Reverse Proxy Server (ตอ) • In reverse proxy mode, the proxy server functions more like a web server with respect to the clients it services. Unlike internal clients, external clients are not preconfigured to access the proxy server. Instead, the site URL routes the client to the proxy as if it were a web server. Replicated content is delivered from the proxy cache to the external client without exposing the origin server or the private network residing safely behind the firewall. Multiple reverse proxy servers can be used to balance the load on an over- taxed web server in much the same way. • Reverse proxy servers are commonly used for secure web publishing. Having a proxy server accepting and filling outside requests allows you to keep your web server behind the firewall. You can then use the web server as a protected web site, staging documents for testing before they are published externally. When you are ready, you can publish selected content to the reverse proxy server's cache.