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
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 (ตอ)
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
31. การสราง web page เพื่อแจงเตือนสําหรับ web ตองหาม
สรางขอความเตือนในรูปแบบ HTML จาก Editor หรือ
โปรแกรมสําหรับสราง Web page
นําไฟลที่สรางเสร็จไปทับไฟลที่
/etc/squid/errors/ERR_ACCESS_DENIED
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.