วิธีทำ Virtual Host บน XAMPP ในระบบปฏิบัติการ Windows

วิธีทำ Virtual Host บน XAMPP ในระบบปฏิบัติการ Windows

Virtual Host คืออะไร ?

Virtual Host คือ การทำให้ Server เครื่องเดียวสามารถให้บริการได้มากกว่า 1 เว็บไซต์ ซึ่งโดยปกติสามารถให้บริการได้เพียงเว็บไซต์เดียว การทำ Virtual Host สามารถทำได้หลายวิธี ดังนี้

  1. Name-based Virtual Host - การอ้างอิงโดยใช้ Domain Name หรือ Host Name
  2. Port-based Virtual Host - การอ้างอิงโดยใช้ Port Number
  3. IP-based Virutal Host - การอ้างอิงโดยใช้ IP Address
  4. การใช้ทั้ง Port-based ร่วมกับ IP-based
  5. การใช้ทั้ง Name-based ร่วมกับ IP-based

เริ่มต้นการทำ Virtual Host แบบ Step By Step

การทำ Virtual Host บน XAMPP ในระบบปฏิบัติการ Window  ต้องแก้ไขไฟล์ดังนี้

  • httpd-vhosts.conf
  • hosts

ขั้นตอนที่ 1 แก้ไข httpd-vhosts.conf

ไปที่ C:\xampp\apache\conf\extra\httpd-vhosts.conf เปิดไฟล์ขึ้นมา หาคำว่า NameVirtualHost แก้ไขให้เป็น

NameVirtualHost *:80

กำหนด Virtual Host ของ localhost เพื่อให้สามารถใช้ localhost ได้เหมือนเดิม

<VirtualHost *:80>
    DocumentRoot c:/xampp/htdocs
    ServerName localhost
    <Directory c:/xampp/htdocs>
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order Deny,Allow
        Allow from all
    </Directory>
</VirtualHost>

 

ต่อมาทำการเพิ่มชื่อ Domain Name หรือ Host Name เพื่ออ้างอิงไปยัง Path ที่เก็บเว็บไซต์ที่ต้องการและกำหนดสิทธิ์การเข้าถึง

<VirtualHost *:80>
    DocumentRoot c:/xampp/htdocs/share/public
    ServerName share.olanlab.com
    <Directory c:/xampp/htdocs/share/public>
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order Deny,Allow
        Allow from all
    </Directory>
</VirtualHost>

ตัวอย่างด้านบน

Path ที่เก็บเว็บไซต์เป็น - c:/xamp/htdocs/share/public

Domain Name เป็น     - share.olanlab.com

 

ขั้นตอนที่ 2 แก้ไข hosts 

ไปที่ C:\Windows\System32\drivers\etc\hosts เปิดไฟล์ขึ้นมาทำการเพิ่ม Host Name และ IP Address  เพื่อให้เครื่องของเรารู้จักชื่อ Host Name นี้ว่าจะต้องไปที่ IP Adress อะไร

127.0.0.1       localhost
127.0.0.1       share.olanlab.com

*ไฟล์ hosts ทำหน้าที่เก็บข้อมูล Host Name กับ IP Address ที่ตรงกัน 

 

ขั้นตอนที่ 3 ทำการ Restart Apache

ขั้นตอนสุดท้ายคือการ Restart Apache เพื่อให้ Apache ทำการโหลดค่าที่เรากำหนดใน httpd-vhosts.conf ใหม่เท่านี้ก็สามารถใช้ Virtual Host บน XAMPP ในระบบปฏิบัติการ Window ได้แล้วครับ

  • 3 Utilisateurs l'ont trouvée utile
Cette réponse était-elle pertinente?

Related Articles

อัพเกรด Windows Server 2012 Trail To Full

How to upgrade Windows Server 2012 R2 evaluation version to full version 8 Replies On a...

สอนลง openssh บน ubuntu

วิธีติดตั้ง SSH บน Ubuntu 1. ติดตั้ง SSH 1 sudo apt-get install...

สอนตั้งค่า Network บน CentOS7

After installing Centos 7, You may not able to connect network in that machine. This will happen...

(Vmware) How to install VMware Tools on Debian, Ubuntu and CentOS

How to install VMware Tools on Debian, Ubuntu and CentOS go to VM > Guest >...

How to enable root user ssh login in Ubuntu 16.04, 17.04, 18.04, 19.04

How to enable root user ssh login in Ubuntu 16.04, 17.04, 18.04 , 19.04 Remote login with root...

Powered by WHMCompleteSolution