Subdomain คืออะไร? วิธีสร้างและจัดการ Subdomain บน Hosting ไทย 2026
Subdomain คือการแบ่งโดเมนหลักออกเป็นส่วนย่อยๆ โดยเพิ่มคำหน้าโดเมนหลัก เช่น blog.example.com, shop.example.com หรือ api.example.com การใช้ subdomain ช่วยจัดระเบียบเว็บไซต์ขนาดใหญ่ และแยก service ต่างๆ ออกจากกันอย่างชัดเจน
A subdomain is a subdivision of your main domain, created by adding a prefix before the main domain — e.g., blog.example.com, shop.example.com, or api.example.com. Subdomains help organize large websites and clearly separate different services.
Subdomain คืออะไร?
ในโครงสร้าง DNS, subdomain คือส่วนที่อยู่ก่อน Second-Level Domain (SLD) ตัวอย่างเช่น:
- blog.example.com — subdomain "blog" ของ example.com
- shop.example.com — subdomain "shop" สำหรับร้านค้าออนไลน์
- staging.example.com — subdomain "staging" สำหรับทดสอบก่อน deploy
- api.example.com — subdomain "api" สำหรับ REST API endpoints
- mail.example.com — subdomain ที่ระบบจัดการ email ใช้บ่อย
In DNS structure, a subdomain is the part before the Second-Level Domain (SLD). Examples: blog.example.com (blog subdomain), shop.example.com (online store), staging.example.com (testing environment), api.example.com (REST API), mail.example.com (email server).
ทำไมต้องใช้ Subdomain?
เหตุผลที่นักพัฒนาและเจ้าของเว็บไซต์เลือกใช้ subdomain:
- แยก service ออกจากกัน: blog, shop, app ทำงานอิสระ ไม่รบกวนกัน
- Staging environment: ทดสอบ code ใหม่ก่อน deploy ไป production
- หลาย CMS/Framework: main site ใช้ WordPress, shop ใช้ WooCommerce แยก, API ใช้ Laravel
- จัดการ SSL แยก: แต่ละ subdomain ออก SSL เฉพาะตัวได้ หรือใช้ Wildcard SSL ครอบทุกตัว
- Analytics แยก: ติดตาม traffic แต่ละ subdomain แยกกันได้ชัดเจน
สร้าง Subdomain ใน DirectAdmin
DirectAdmin ทำให้การสร้าง subdomain ง่ายมาก ทำได้ใน 3 ขั้นตอน:
- Login DirectAdmin → ไปที่ Domain Setup หรือ Subdomain Management
- กรอก subdomain ที่ต้องการ เช่น "blog" (ระบบจะสร้าง blog.yourdomain.com ให้อัตโนมัติ)
- เลือก Document Root (โฟลเดอร์ที่เก็บไฟล์เว็บของ subdomain นี้)
- คลิก Create → รอสักครู่ subdomain จะพร้อมใช้งานทันที
Creating subdomains in DirectAdmin: 1) Login → Domain Setup or Subdomain Management. 2) Enter subdomain name (e.g., "blog" — system creates blog.yourdomain.com). 3) Choose Document Root for files. 4) Click Create — subdomain ready immediately.
DNS Record สำหรับ Subdomain
เมื่อสร้าง subdomain ผ่าน DirectAdmin ระบบจะสร้าง A Record ใน DNS อัตโนมัติ โดยชี้ IP ไปยัง server เดียวกัน แต่ถ้าต้องการชี้ subdomain ไป server อื่น ต้องแก้ DNS Record ด้วยตัวเอง:
- A Record: ชี้ subdomain ไปยัง IP address ของ server
- CNAME Record: ชี้ subdomain ไปยัง hostname อื่น (เช่น ชี้ไป Cloudflare Pages หรือ GitHub Pages)
SSL สำหรับ Subdomain
ทุก subdomain ต้องการ SSL แยกต่างหาก มีสองแนวทาง:
- Let's Encrypt แยกทีละ subdomain: ใน DirectAdmin → SSL Certificates → ออก Let's Encrypt สำหรับ subdomain นั้นๆ ฟรี
- Wildcard SSL (*.example.com): ครอบทุก subdomain ในใบเดียว เหมาะถ้ามี subdomain หลายตัว
Each subdomain needs its own SSL. Two options: 1) Issue Let's Encrypt per subdomain via DirectAdmin (free). 2) Get Wildcard SSL (*.example.com) to cover all subdomains in one certificate — cost-effective for many subdomains.
ติดตั้ง WordPress บน Subdomain
- สร้าง subdomain ใน DirectAdmin (เช่น blog.example.com) → กำหนด document root
- สร้าง Database ใหม่สำหรับ subdomain นี้ใน MySQL Management
- Upload WordPress ไปยัง document root ของ subdomain
- รัน WordPress installer ผ่าน http://blog.example.com/wp-admin/install.php
- ออก SSL สำหรับ blog.example.com ใน SSL Certificates
Subdomain vs Subfolder: อันไหนดีกว่า SEO?
คำถามที่พบบ่อยในวงการ SEO: blog.example.com (subdomain) กับ example.com/blog (subfolder) อันไหนดีกว่า?
Google ปฏิบัติต่อทั้งสองอย่างเท่าเทียมกัน แต่ในทางปฏิบัติ subfolder มักได้เปรียบเพราะ:
- Link equity จาก main domain ส่งถึงกันได้โดยตรง
- Google ต้องไม่ crawl แยก domain ใหม่
- บทความ blog ได้ประโยชน์จาก domain authority ของ main site เต็มๆ
แต่ถ้า service นั้นแตกต่างจาก main site มาก (เช่น app, api, staging) ให้ใช้ subdomain
Google treats both equally, but subfolders often have practical SEO advantages: direct link equity from main domain, no separate crawling needed, blog posts benefit from main site domain authority. Use subdomains when services are fundamentally different (app, api, staging).
Use Cases ยอดนิยมสำหรับ Subdomain
- blog.domain.com — Content marketing blog
- shop.domain.com — ร้านค้าออนไลน์แยกจาก corporate site
- app.domain.com — Web application หรือ SaaS product
- staging.domain.com — Test environment ก่อน deploy
- api.domain.com — REST API endpoints
- docs.domain.com — Documentation site
- support.domain.com — Help desk หรือ ticketing system
- cdn.domain.com — Static assets serving
คำถามที่พบบ่อย (FAQ)
subdomain ใช้งานได้เลยไหม หรือต้องรอ DNS propagate?
ถ้าสร้าง subdomain ผ่าน DirectAdmin และ DNS อยู่กับ hosting เดียวกัน มักใช้งานได้เลยหรือรอไม่กี่นาที แต่ถ้า DNS อยู่ที่ domain registrar อื่น อาจต้องรอ propagate 15-60 นาที
สร้าง subdomain ได้กี่ตัว?
ขึ้นอยู่กับ hosting plan แต่ส่วนใหญ่ไม่จำกัด หรือจำกัดที่จำนวนโดเมน/addon domain ที่ plan อนุญาต ตรวจสอบกับ hosting provider ของคุณ
subdomain กับ addon domain ต่างกันยังไง?
Subdomain ใช้ domain เดิม เช่น blog.example.com Addon domain คือโดเมนใหม่ทั้งหมด เช่น newdomain.com ที่ชี้ไปยัง hosting เดียวกัน ทั้งสองใช้พื้นที่ hosting เดียวกัน
ถ้าลบ subdomain แล้วไฟล์จะหายไปด้วยไหม?
การลบ subdomain ใน DirectAdmin จะลบ DNS record และ config เท่านั้น ไฟล์ใน document root ยังอยู่ครบ คุณต้องลบไฟล์เองถ้าต้องการเคลียร์พื้นที่