June 24, 2017
ตัวอย่าง การใช้ Apache สร้าง Virtual Host โดยแยกตามโดเมน
ตัวอย่าง การใช้ Apache สร้าง Virtual Host โดยแยกตามโดเมน
สมมติ ในที่นี้ผมมี domain อยู่ 2 โดเมน คือ doesystem.info กับ doesystem.com
โดย doesystem.info ผมจะให้มัน reverse ไปที่ port 3000
ส่วน doesystem.com ผมจะให้มัน reverse ไปที่ port 3001
ในที่นี้ผมจะใช้ตัว Apache ทำให้มันเป็น Virtual Host แล้วทำการ reverse ไปตามพอร์ตที่ต้องการ
ก่อนอื่นผมก็ไปเปิดใช้ Virtual hosts โดยเข้าไปที่ conf/httpd.conf จากนั้นมองหา
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
แล้วทำการเอาคอมเม้นออก เพื่อทำการ include ไฟล์ httpd-vhosts.conf เข้ามาใช้ด้วยใน Project
จากนั้นเราก็ไปทำการ config virtual host ในไฟล์ที่ชื่อว่า httpd-vhosts.conf เมื่อเข้าไปแล้ว ผมก็เพิ่ม
ServerAdmin [email protected]
ServerName www.doesystem.info
ProxyPreserveHost On
# setup the proxy
Order allow,deny
Allow from all
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
ServerAdmin [email protected]
ServerName www.doesystem.com
ProxyPreserveHost On
# setup the proxy
Order allow,deny
Allow from all
ProxyPass / http://localhost:3001/
ProxyPassReverse / http://localhost:3001/
เพียงแคนี้เวลาเข้ามาจากโดเมน doesystem.info มันก็จะ reverse ไปที่ http://localhost:3000 ส่วนเวลาเข้าจาก doesystem.con มันก็จะ reverse ไปที่ http://localhost:3001