
Proxy Server: ตั้งค่า Squid Proxy สำหรับองค์กร
Proxy Server เป็นตัวกลางระหว่าง users กับ internet ทุก request จาก users จะผ่าน proxy ก่อนออกไป internet proxy สามารถ cache content ที่เข้าถึงบ่อย (ลด bandwidth), filter websites ที่ไม่เหมาะสม (web filtering), log การใช้งาน internet (compliance), และป้องกัน malware จาก web traffic
Squid เป็น proxy server ที่นิยมที่สุดในโลก open-source เป็น forward proxy และ reverse proxy (web accelerator) ได้ รองรับ HTTP, HTTPS, FTP มี caching engine ที่ทรงพลัง ใช้ในองค์กรตั้งแต่ SME ไปจนถึง ISP ระดับใหญ่ บทความนี้จะสอนวิธีติดตั้งและตั้งค่า Squid สำหรับองค์กร
ประเภทของ Proxy
| ประเภท | ทิศทาง | ใช้ทำอะไร | ตัวอย่าง |
|---|---|---|---|
| Forward Proxy | Client → Proxy → Internet | Web filtering, caching, logging | Squid, BlueCoat |
| Reverse Proxy | Internet → Proxy → Web Server | Load balancing, SSL termination, caching | Nginx, HAProxy, Varnish |
| Transparent Proxy | Client → Proxy (ไม่รู้ตัว) → Internet | เหมือน Forward แต่ไม่ต้องตั้งค่า client | Squid (transparent mode) |
| SOCKS Proxy | Application-level proxy | Proxy ทุก protocol (ไม่ใช่แค่ HTTP) | Dante, SSH SOCKS |
ติดตั้ง Squid Proxy บน Ubuntu
Step 1: ติดตั้ง
ติดตั้ง Squid ด้วย apt install squid ไฟล์ configuration หลักอยู่ที่ /etc/squid/squid.conf Squid listen บน port 3128 เป็น default
Step 2: Basic Configuration
ตั้งค่า ACL (Access Control List) กำหนดว่า network ไหนใช้ proxy ได้ เช่น acl localnet src 10.0.0.0/8 เปิด access ด้วย http_access allow localnet ตั้ง cache directory (cache_dir ufs /var/spool/squid 10000 16 256 = 10GB cache) ตั้ง visible_hostname สำหรับ error pages
Web Filtering ด้วย Squid
Block Websites ด้วย ACL
สร้างไฟล์ blocked_sites.txt ใส่ domain ที่ต้องการ block (เช่น facebook.com, youtube.com, gambling sites) สร้าง ACL ใน squid.conf: acl blocked_sites dstdomain “/etc/squid/blocked_sites.txt” กำหนด http_access deny blocked_sites users ที่พยายามเข้า website ที่ถูก block จะเห็น error page ของ Squid
Block ตาม Content Type
Block file types ที่ไม่ต้องการ เช่น .exe, .torrent, .mp4 สร้าง ACL: acl blocked_extensions urlpath_regex -i \.(exe|torrent|mp4|avi|mkv)$ กำหนด http_access deny blocked_extensions ป้องกัน users download ไฟล์ที่อาจเป็น malware หรือใช้ bandwidth มากเกินไป
Time-based Access Control
อนุญาตให้เข้า social media เฉพาะช่วงพักเที่ยง สร้าง ACL time: acl lunch_time time MTWHF 12:00-13:00 กำหนด: http_access allow social_sites lunch_time http_access deny social_sites นอกเวลาพัก social media จะถูก block
HTTPS Interception (SSL Bump)
ทำไมต้อง SSL Bump
ปัจจุบัน 90%+ ของ web traffic เป็น HTTPS Squid ไม่สามารถเห็น URL ของ HTTPS traffic ได้ (encrypted) ถ้าไม่ทำ SSL Bump จะ filter ได้แค่ domain (SNI) ไม่สามารถ filter URL path หรือ content ได้ SSL Bump ให้ Squid decrypt HTTPS traffic ตรวจสอบ แล้ว re-encrypt ส่งต่อ
ข้อควรระวัง
SSL Bump เป็น man-in-the-middle โดยเจตนา ต้อง deploy CA certificate ของ Squid ไปยังทุก client ใน network (ผ่าน GPO, MDM) อาจมีผลกระทบด้าน privacy ต้องมี policy ชัดเจนว่าจะ inspect traffic อะไรบ้าง บาง applications อาจไม่ทำงานกับ SSL Bump (certificate pinning) ต้อง exclude จาก interception
Squid Caching
ประโยชน์ของ Caching
Caching ลด bandwidth ได้ 20-40% content ที่ users เข้าถึงบ่อย (Windows updates, software updates, JS/CSS libraries) จะถูก cache ใน Squid request ถัดไปจะได้ content จาก cache ไม่ต้องดาวน์โหลดซ้ำ ลด latency สำหรับ users ลด bandwidth cost สำหรับองค์กร
Cache Configuration
กำหนด cache size ตาม disk space ที่มี (แนะนำ 10-50GB สำหรับ SME) กำหนด maximum_object_size (ขนาดไฟล์สูงสุดที่จะ cache เช่น 100MB) กำหนด cache_mem (RAM สำหรับ hot cache เช่น 256MB-1GB)
Transparent Proxy
ทำไมต้อง Transparent
Transparent proxy ไม่ต้องตั้งค่า proxy settings บน client ทุกเครื่อง traffic จาก port 80/443 จะถูก redirect ไปยัง Squid อัตโนมัติ (ด้วย iptables REDIRECT) เหมาะสำหรับ BYOD environment ที่ไม่สามารถ control client settings ได้
Squid Performance Tuning
| Parameter | Default | แนะนำ (500 users) | คำอธิบาย |
|---|---|---|---|
| cache_mem | 256 MB | 1024 MB | RAM cache สำหรับ hot objects |
| maximum_object_size_in_memory | 512 KB | 2 MB | ขนาดสูงสุดที่เก็บใน RAM cache |
| cache_dir size | 100 MB | 20000 MB (20GB) | Disk cache size |
| maximum_object_size | 4 MB | 100 MB | ขนาดสูงสุดที่จะ cache บน disk |
| dns_nameservers | system default | 8.8.8.8 1.1.1.1 | DNS สำหรับ Squid |
ทิ้งท้าย: Proxy ยังจำเป็นในยุค Cloud
แม้จะมี cloud security services (Zscaler, Cloudflare Gateway) แต่ on-premise proxy อย่าง Squid ยังมีประโยชน์ ลด bandwidth ด้วย caching, web filtering สำหรับ compliance, logging สำหรับ audit และราคาถูก (ฟรี) เหมาะสำหรับ SME ที่มี budget จำกัด
อ่านเพิ่มเติมเกี่ยวกับ Firewall Configuration และ Web Security ที่ siamlancard.com หรือจาก icafeforex.com และ siam2r.com