Apache配置虚拟主机

1、修改Apache主配置文件

[root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf
Include conf/extra/httpd-vhosts.conf

2、修改虚拟主机文件

<VirtualHost *:80>
#    ServerAdmin [email protected]
[root@localhost two.com]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
    DocumentRoot "/usr/local/apache2/htdocs/one.com"  //网页文档配置路径
    ServerName www.one.com    //虚拟主机名称
    ServerAlias www.1.com     //虚拟主机别名
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache2/htdocs/two.com"
    ServerName www.two.com
    ServerAlias www.1.com
</VirtualHost>

3、创建网页配置文件

[root@localhost htdocs]# mkdir one.com two.com
[root@localhost htdocs]# cd one.com
[root@localhost one.com]# echo "This is  first page" >index.html
[root@localhost htdocs]# cd two.com/
[root@localhost two.com]# echo "This is  second page" >index.html

4、测试

[root@localhost two.com]# /usr/local/apache2/bin/apachectl restart
[root@localhost two.com]# curl www.one.com
This is  first page
[root@localhost two.com]# curl www.two.com
This is  second page


你可能感兴趣的:(local,配置文件,网页,虚拟主机)