คลังเก็บป้ายกำกับ: URL

ทำ DNS (Domain Name System) ส่วนตัว

เวลาเขียนระบบใหญ่ๆ ที่สัมพันธ์กันหลาย domain หรือเขียน blog ที่ลูกค้าต้องการให้แต่ละตัวมี private domain เป็นภายในของตัวเอง เช่น pitt.plusmagi.internal ,dev.plusmagi.internal ถ้ามี network มาช่วย set domain ไว้เทสได้ก็ดี
หรือจะสร้าง dns ส่วนตัวไว้ใช้เฉพาะเครื่องที่เป็น server ก็จะง่ายกว่าครับ ( วิธีนี้มีผลเฉพาะเครื่องที่เราทำไว้เท่านั้น )

  1. เปิดไฟล์ hosts โดย
    • Linux หรือ macOS
      • ใช้คำสั่ง
        sudo nano /etc/hosts
    • Windows
      • เปิดไฟล์ C:\Windows\system32\drivers\etc\hosts ถ้าเป็น windows รุ่นหลังต้องเอา read only และกำหนดสิทธิให้เขียนได้ก่อนครับ
  2. เพิ่ม บรรทัดโดยมีรูปแบบ เช่น
    127.0.0.1 { domain name }
    เช่น
    127.0.0.1 plusmagi.internal ลงไป
  3. ถ้าต้องการเพิ่ม domain อื่น ๆ ก็เพิ่มบรรทัด 127.0.0.1 domain ลงไปเรื่อย ๆ เช่น
    #private internal DNS
    127.0.0.1 api.plusmagi.internal
    127.0.0.1 backend.plusmagi.internal
    127.0.0.1 frontend.plusmagi.internal
    127.0.0.1 phunsanit.plusmagi.internal
    127.0.0.1 pitt.plusmagi.internal
    127.0.0.1 plusmagi.internal
    127.0.0.1 www.plusmagi.internal
    # End of private internal DNS
    
  4. ถ้าต้องการใช้ server ใน WSL จะต้องเพิ่ม ::1 ไปอีกรายการละ 1 บรรทัด ใน C:\Windows\system32\drivers\etc\hosts ตัว WSL จะเห็นเอง เช่น
    #private internal DNS
    127.0.0.1 api.plusmagi.internal
    ::1 api.plusmagi.internal
    127.0.0.1 backend.plusmagi.internal
    ::1 backend.plusmagi.internal
    127.0.0.1 frontend.plusmagi.internal
    ::1 frontend.plusmagi.internal
    127.0.0.1 phunsanit.plusmagi.internal
    ::1 phunsanit.plusmagi.internal
    127.0.0.1 pitt.plusmagi.internal
    ::1 pitt.plusmagi.internal
    127.0.0.1 plusmagi.internal
    ::1 plusmagi.internal
    127.0.0.1 www.plusmagi.internal
    ::1 www.plusmagi.internal
    # End of private internal DNS
    
  5. ไปที่ browser แล้วพิมพ์ URL ว่า http://plusmagi.internal จะเป็นการดึงข้อมูลจากเครื่องเราครับ

อ่านเพิ่มเติม