Thứ Năm, 20 tháng 12, 2012

Cấu hình virtualhost apache2 trên ubuntu 12.04


Dưới đây là các bước cấu hình.
1. Cấu hình Virtual Hostings
root@www:~# vi /etc/apache2/sites-available/virtual.host
# create a file for virtual.host
<VirtualHost *:80>
ServerName www.virtual.host
ServerAdmin webmaster@virtual.host
DocumentRoot /home/narwhal/public_html
ErrorLog /var/log/apache2/virtual.host.error.log
CustomLog /var/log/apache2/virtual.host.access.log combined
LogLevel warn
root@www:~# a2ensite virtual.host
Enabling site virtual.host.
Run ‘/etc/init.d/apache2 reload’ to activate new configuration!
root@www:~# /etc/init.d/apache2 reload
* Reloading web server config apache2
…done.
2. Tạo 1 file test, sau đó truy cập vào, nếu hiện thị có nghĩa là cấu hình OK
narwhal@www:~$ cd public_html
narwhal@www:~/public_html$ vi virtual.php

<html>
<body>
<div style=”width: 100%; font-size: 40px; font-weight: bold; text-align:center;”>
Virtual Host Test Page<br />
<?php
print Date(“Y/m/d”);
?>
</div>
</body>
</html>

- Mở file /etc/hosts bằng chương trình soạn thảo text bất kỳ với quyền Administrator
 - Thêm dòng mã 127.0.0.1 localhost.localdomain localhost test.domain.com www.test.domain.com
 - Lưu và đóng file đó lại.
Khởi động lại Apache với lệnh sudo /etc/init.d/apache2 restart và kiểm tra virtual host bằng cách gõ địa chỉ vào trình duyệt.
Nguồn: tailieulinux.com

0 nhận xét:

Đăng nhận xét