Subdomain คืออะไร ใช้ทำอะไร ตั้งค่าอย่างไร
What is a Subdomain? Uses, how to create one, DNS settings, and when to use subdomain vs subdirectory.
สารบัญ
Subdomain คืออะไร
Subdomain คือส่วนหน้าของ Domain Name ที่แยกออกมา เช่น ถ้า Domain หลักคือ example.com แล้วมี blog.example.com, shop.example.com หรือ mail.example.com สิ่งเหล่านี้คือ Subdomain ชี้ไปที่ IP หรือ Server ที่แตกต่างกันได้
A subdomain is a prefix segment of a domain name. If the main domain is example.com, then blog.example.com, shop.example.com, or mail.example.com are subdomains — each can point to different IP addresses or servers.
- blog.example.com: Subdomain สำหรับ Blog
- shop.example.com: Subdomain สำหรับ E-commerce
- mail.example.com: สำหรับ Mail Server
- staging.example.com: สำหรับ Test Environment
- api.example.com: สำหรับ API Endpoint
Subdomain ใช้ทำอะไรได้บ้าง
Subdomain ใช้ได้หลากหลาย เช่น แยก Blog ออกจากเว็บหลัก, แยก E-commerce Store, ทำ Staging Environment สำหรับทดสอบ, ทำ API Endpoint, ทำ CDN ให้รูปภาพ, ทำ Mobile Version ของเว็บ, หรือแยก Regional Site
Subdomains have many uses: separating a blog from the main site, isolating an e-commerce store, creating staging environments for testing, API endpoints, CDN for images, mobile versions of websites, or regional sites.
- blog.example.com: แยก Blog จาก Main Site
- store.example.com: E-commerce แยก Platform
- staging.example.com: ทดสอบก่อน Deploy
- api.example.com: REST API Endpoint
- cdn.example.com: Serve รูปภาพจาก CDN
Subdomain vs Subdirectory ต่างกันอย่างไร
Subdomain (blog.example.com) และ Subdirectory (example.com/blog) ต่างกันที่ Subdomain สร้าง Entity ใหม่แยกต่างหาก สามารถ Host บน Server ต่างกัน ใช้ CMS ต่างกันได้ Subdirectory ใช้ Server เดิม Config เดิม ง่ายกว่าในแง่ SEO
Subdomain (blog.example.com) vs Subdirectory (example.com/blog): subdomains create separate entities that can be hosted on different servers with different CMS. Subdirectories use the same server and configuration, and are generally simpler for SEO.
- Subdomain: แยก Server, CMS ได้อิสระ
- Subdirectory: Server เดิม, Config เดิม
- SEO: Subdirectory มักดีกว่าสำหรับ Blog เดียวกัน
- Subdomain: ดีสำหรับ Platform ต่างกัน (Node/PHP)
- Google: บอกว่าไม่แตกต่าง แต่ในทางปฏิบัติ Subdirectory ดีกว่า
ตั้งค่า DNS สำหรับ Subdomain
สร้าง Subdomain โดยเพิ่ม A Record หรือ CNAME Record ใน DNS Zone ของ Domain ถ้า Subdomain ชี้ไป IP เดียวกับ Root Domain ใช้ A Record ชี้ IP เดียวกัน ถ้าชี้ไป Domain อื่น (เช่น CDN, GitHub Pages) ใช้ CNAME Record
Create a subdomain by adding an A Record or CNAME Record to the domain's DNS zone. If the subdomain points to the same IP as the root domain, use an A Record with the same IP. If pointing to another domain (CDN, GitHub Pages), use a CNAME Record.
- A Record: blog → 1.2.3.4 (ชี้ IP)
- CNAME Record: shop → shopify.example.com (ชี้ Domain)
- Propagation: ใช้เวลา 30 นาที - 24 ชั่วโมง
- TTL: กำหนดระยะเวลา Cache DNS
- ตรวจสอบ: dig blog.example.com หรือ nslookup
ตั้งค่า Subdomain บน Hosting
ที่ cPanel หรือ DirectAdmin ไปที่ Subdomains Section เพิ่ม Subdomain ชื่อ เช่น blog และ Document Root เช่น /public_html/blog ระบบสร้าง Folder ให้อัตโนมัติ อัพโหลดไฟล์ไปใน Folder นั้น Subdomain พร้อมใช้งาน
In cPanel or DirectAdmin, go to Subdomains section, add the subdomain name (e.g., blog) and document root (e.g., /public_html/blog). The system automatically creates the folder. Upload files to that folder and the subdomain is ready.
- cPanel: Subdomains → เพิ่ม Subdomain
- DirectAdmin: Subdomains → Create Subdomain
- Document Root: ตั้ง Path ที่ต้องการ
- ระบบสร้าง Folder ให้อัตโนมัติ
- SSL: ขอ SSL สำหรับ Subdomain แยก
Subdomain กับ SEO
Subdomain และ Subdirectory มีผลต่อ SEO แตกต่างกัน Google ถือว่า Subdomain เป็น Entity แยก บางกรณีต้องสร้าง Authority ใหม่สำหรับ Subdomain ในขณะที่ Subdirectory แชร์ Authority กับ Root Domain สำหรับ Blog หรือ Content ที่ต้องการ SEO ผล Subdirectory แนะนำกว่า
Subdomains and subdirectories affect SEO differently. Google treats subdomains as separate entities — sometimes requiring rebuilding authority. Subdirectories share the root domain's authority. For blogs or SEO-driven content, subdirectories are generally preferable.
- Subdomain: Google บอกไม่ต่าง แต่ในทางปฏิบัติ Authority แยก
- Subdirectory: แชร์ Authority กับ Root Domain
- Blog SEO: Subdirectory ดีกว่าสำหรับ Content Site
- Separate Product: Subdomain ดีกว่า (เช่น Store)
- Internal Link: Subdomain ต้องสร้าง Link เข้าจาก Root
Wildcard Subdomain
Wildcard Subdomain (*.example.com) รับ Request ทุก Subdomain ที่ไม่ได้ Define ไว้ ใช้สำหรับ Multi-tenant Application เช่น username.example.com หรือ customer.example.com ต้องตั้งค่า DNS Wildcard A Record และ Hosting รองรับ Wildcard
Wildcard subdomain (*.example.com) accepts requests for any subdomain not explicitly defined — used for multi-tenant applications like username.example.com or customer.example.com. Requires wildcard DNS A Record and hosting support for wildcards.
- *.example.com: รับทุก Subdomain
- Multi-tenant SaaS: username.platform.com
- Wildcard SSL: ครอบคลุมทุก Subdomain ด้วย
- DNS: A Record * → IP
- Server Config: ต้องรองรับ Wildcard Virtual Host
ตัวอย่างการใช้ Subdomain จริง
ตัวอย่าง Subdomain ที่นิยม: docs.example.com สำหรับ Documentation, status.example.com สำหรับ Status Page, app.example.com สำหรับ Web App, en.example.com และ th.example.com สำหรับ Multilingual Site, m.example.com สำหรับ Mobile Version
Popular real-world subdomain examples: docs.example.com for documentation, status.example.com for status pages, app.example.com for web apps, en/th.example.com for multilingual sites, m.example.com for mobile versions.
- docs.example.com: Documentation Site
- status.example.com: Server Status Page
- app.example.com: Web Application
- en/th.example.com: Multilingual Region
- help.example.com: Help Center
สรุปขั้นตอนสร้าง Subdomain
1. เพิ่ม DNS Record (A หรือ CNAME) ที่ DNS Provider 2. รอ Propagation 30 นาที - 24 ชั่วโมง 3. ตั้งค่าที่ Hosting (cPanel/DirectAdmin) 4. ขอ SSL Certificate สำหรับ Subdomain 5. ทดสอบว่า HTTPS ทำงานได้
Step-by-step: 1. Add DNS Record (A or CNAME) at DNS provider 2. Wait 30 min to 24 hours for propagation 3. Configure at hosting (cPanel/DirectAdmin) 4. Request SSL certificate for subdomain 5. Test HTTPS functionality.
- Step 1: เพิ่ม A หรือ CNAME ที่ DNS Provider
- Step 2: รอ DNS Propagation
- Step 3: เพิ่ม Subdomain ที่ cPanel/DirectAdmin
- Step 4: ขอ SSL (Let's Encrypt ฟรี)
- Step 5: ทดสอบ https://subdomain.yourdomain.com