二、Apache服务器配置
1.首先创建测试需要用到的主面文件,如下:
[root@itpro html]# ls
index.html op sq
[root@itpro html]# cat index.html
this is home page
server: 192.168.56.53
[root@itpro html]# cat op/index.html
this is op page
server: 192.168.56.53
[root@itpro html]# cat sq/index.html
this is sq page
server: 192.168.56.53
2.修改主配文件/etc/httpd/conf/httpd.conf
首先启用NameVirtualHost字段,该字段为一个基于域名的虚拟主机指定一个IP地址,*表示本机当前使用的IP地址。
NameVirtualHost *:80 #这一行默认是注释掉了的,要将其前面的#去掉
然后在文件末尾增加以下内容:
<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/html #文档的根目录。默认情况下,所有的请求从这个目录进行应答
ServerName 192.168.56.53 #机子的名称,用IP地址或域名表示
# ErrorLog logs/dummy-host.example.com-error_log #可以指定错误日志存放目录,若不指定,默认是在/etc/httpd/logs/access_log里
# CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html/op
ServerName www.op.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html/sq
ServerName www.sq.com
</VirtualHost>
3.重启httpd服务
[root@itpro ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: apr_sockaddr_info_get() failed for zoro
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
