- 论坛徽章:
- 0
|
这两天有两位朋友在谈论虚拟主机的问题,并且一至没有得到解决。今天在自己的机器上简单做了一下。现在把过程给大家说一下,希望对那两位朋友和其他在做虚拟主机的朋友有所帮助。
说明:用的RHAS3自带的bind和apache。
一、DNS的实现
1.vi /etc/named.conf
加入:
CODE:
[Copy to clipboard]
zone "test1.com" IN {
type master;
file "test1.zone";
allow-update { none; };
};
zone "test2.com" IN {
type master;
file "test2.zone";
allow-update { none; };
};
zone "0.168.192.in-addr.arpa" IN {
type master;
file "test.reslove";
allow-update { none; };
};2.cd /var/named
# cp localhost.zone test1.zone
# cp named.local test.reslove
3.vi test1.zone
内容修改如下:
CODE:
[Copy to clipboard]
$TTL 86400
@ IN SOA ns.test1.com. root.test1.com. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS ns.test1.com.
www IN A 192.168.0.1
ftp IN A 192.168.0.1
mail IN A 192.168.0.1
test1.com. IN MX 10 mail.test1.com.4.cp test1.zone test2.zone
然后把所有的test1换成test2,修改后内容如下:
CODE:
[Copy to clipboard]
$TTL 86400
@ IN SOA ns.test2.com. root.test2.com. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS ns.test2.com.
www IN A 192.168.0.1
ftp IN A 192.168.0.1
mail IN A 192.168.0.1
test2.com. IN MX 10 mail.test2.com.5.vi test.reslove,内容修改为:
CODE:
[Copy to clipboard]
$TTL 86400
@ IN SOA ns.test1.com. root.test1.com. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS ns.test1.com.
1 IN PTR www.test1.com.
1 IN PTR ftp.test1.com.
1 IN PTR mail.test1.com.
1 IN PTR www.test2.com.
1 IN PTR ftp.test2.com.
1 IN PTR mail.test2.com.6.service named restart
7.vi /etc/resolve.conf在第一行插入
nameserver 192.168.0.1
(注:本机IP为192.168.0.1)
8.ping www.test1.com
ping www.test2.com
ok!已经全部都通了。
nslookup 检查mx记录也都正确。
二、apache中的配置
vi /etc/httpd/conf/httpd.conf
修改下面几处:
1.DirectoryIndex index.htm index.php index.html index.html.var(增加默认首页)
2.AddDefaultCharset GB2312(把默认的UTF-8的字符集修改为简体中文)
3.把#NameVirtualHost *:80修改为NameVirtualHost 192.168.0.1(打开对基于名称的虚拟主机的支持)
4.把下面的虚拟主机的内容修改为下面的内容:
CODE:
[Copy to clipboard]
;
ServerAdmin admin@test1.com
DocumentRoot /data/test1.com
ServerName www.test1.com
;
;
ServerAdmin admin@test2.com
DocumentRoot /data/test2.com
ServerName www.test2.com
;说明:这里去掉了原来的日志和错误信息的选项,如果你需要根据自己的需要修改。
5.mkdir /data/test1.com
cd /data/test1.com
vi index.htm
插入一句:This is test1.com!
6.mkdir /data/test2.com
cp /data/test1.com/index.htm /data/test2.com/
vi /data/test2.com/index.htm
把test1.com改成test2.com
7.service httpd restart
三、检验
打开mozilla输入ttp://www.test1.com看看是不是出来一句话:This is test1.com!
然后输入http://www.test2.com再看看。恭喜你!已经成功了!是不是很简单?
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/6402/showart_77663.html |
|