LAMP环境下虚拟主机配置(基于域名)

在之前LAMP环境下虚拟主机配置(基于IP) 继续做这个基于域名的虚拟主机配置,只需要修改之前的配置内容即可。

一、首先修改一下apache的配置文件
  • 首先修改一下配置文件中的#NameVirtualHost *:80,修改内容如下图所示:
    192.168.3.112是dns sever的地址,即Linux本机IP
1
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf 

1-1.png

  • 然后到文件末尾修改之前的虚拟主机配置文件,如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<VirtualHost 192.168.3.112:80>
ServerAdmin www.zzqa.com
DocumentRoot /var/www/html/zzqa/
ServerName www.zzqa.com
ErrorLog logs/dummy-host.zzqa.com-error_log
CustomLog logs/dummy-host.zzqa.com-access_log common
</VirtualHost>


<VirtualHost 192.168.3.112:80>
ServerAdmin www.zzqb.com
DocumentRoot /var/www/html/zzqb/
ServerName www.zzqb.com
ErrorLog logs/dummy-host.zzqb.com-error_log
CustomLog logs/dummy-host.zzqb.com-access_log common
</VirtualHost>

<VirtualHost 192.168.3.112:80>
ServerAdmin www.zzqc.com
DocumentRoot /var/www/html/zzqc/
ServerName www.zzqc.com
ErrorLog logs/dummy-host.zzqc.com-error_log
CustomLog logs/dummy-host.zzqc.com-access_log common
</VirtualHost>

1-2.png

  • 修改完保存并退出

  • 重启apache服务

1
[root@localhost ~]# service httpd restart

1-3.png

二、修改DNS解析配置
1
2
3
[root@localhost ~]# cd /var/named/
[root@localhost named]# ls
data dynamic named.ca named.empty named.localhost named.loopback sec.com slaves zzqa.com zzqb.com zzqc.com
1
[root@localhost named]# vim zzqa.com 
1
2
3
4
5
6
7
8
9
10
11
12
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
@ IN A 192.168.3.112
www IN A 192.168.3.112
game IN A 192.168.3.112

1
[root@localhost named]# vim zzqb.com
1
2
3
4
5
6
7
8
9
10
11
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
@ IN A 192.168.3.112
www IN A 192.168.3.112
game IN A 192.168.3.112
1
[root@localhost named]# vim zzqc.com
1
2
3
4
5
6
7
8
9
10
11
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
@ IN A 192.168.3.112
www IN A 192.168.3.112
game IN A 192.168.3.112
  • 重启服务
    1
    2
    3
    4
    5
    [root@localhost named]# service named restart

    停止 named:. [确定]
    启动 named: [确定]
    [root@localhost named]#
    三、测试(注意浏览器缓存问题,多刷新几次,只要都正常就是没问题的)

zzqa.com

zzqb.png

zzqc.png