Narisa.com: สร้าง Virtual Host ใน Apache WebServer - Narisa.com

Jump to content

Subscribe to up1's Blog        RSS Feed

สร้าง Virtual Host ใน Apache WebServer

Leave Comment
การ config virtual host ใน apache webserver สามารถทำได้ดังนี้

1. config/httpd.conf ทำการ include file conf/extra/httpd-vhosts.conf ดังนี้

Quote

Include onf/extra/httpd-vhosts.conf


2. ทำการ config ใน file conf/extra/httpd-vhosts.conf เพื่อเพิ่ม virtual host ที่เราต้องการสร้าง ดังนี้

<VirtualHost *:80>
	ServerAdmin admin@xx.com
	DocumentRoot "C:/AppServ/www/my"
	ServerName my.xxx.com
	ErrorLog "logs/my-error.log"
	CustomLog "logs/my-access.log" common
</VirtualHost>

<Directory "C:/AppServ/www/my">
  Order Deny,Allow
  Allow from all
</Directory>


คำอธิบาย
DocumentRoot คือ folder root ของ project
ServerName คือ ชื่อของ virtual ที่เราต้องการสร้าง
ErrorLogม CustomLog คือ log files ต่างๆ ซึ่งจะแยกตาม virtual host


ในการใช้งานในเครื่อง dev บน windows แบบง่ายๆ ก็ไป config ใน file hosts ได้เลย เช่น

Quote

127.0.0.1 my.xxx.com


ถ้าบน linux ก็ไปกำหนดใน file /etc/hosts นะครับ


----- เพิ่มเติม ------
วันนี้เจอปัญหาบน server คือไม่สามารถ access ได้โดยตรง ซึ่งพบว่า ใน file httpd.conf นั้นไม่ได้ allow ในการ access directory ไว้ ดังนั้นวิธีการแก้ไขคือ
- ใน file conf/httpd.conf นั้นกำหนด AllowOverride All
หรือ
- ใน file conf/extra/httpd-vhosts.conf กำหนด AllowOverride All ในแต่ละ virtual host ที่กำหนด

0 Comments On This Entry

 

Search My Blog

September 2010

S M T W T F S
   1234
5678910 11
12131415161718
19202122232425
2627282930